Fixed joystick vendor detection in Linux automatic gamepad mapping

This commit is contained in:
Sam Lantinga 2023-06-13 10:05:19 -07:00
parent 5a62a4596e
commit 071d1e29dd
3 changed files with 6 additions and 4 deletions

View File

@ -118,10 +118,10 @@ static SDL_AtomicInt SDL_last_joystick_instance_id SDL_GUARDED_BY(SDL_joystick_l
static int SDL_joystick_player_count SDL_GUARDED_BY(SDL_joystick_lock) = 0;
static SDL_JoystickID *SDL_joystick_players SDL_GUARDED_BY(SDL_joystick_lock) = NULL;
static SDL_bool SDL_joystick_allows_background_events = SDL_FALSE;
static char joystick_magic;
char SDL_joystick_magic;
#define CHECK_JOYSTICK_MAGIC(joystick, retval) \
if (!joystick || joystick->magic != &joystick_magic) { \
if (!joystick || joystick->magic != &SDL_joystick_magic) { \
SDL_InvalidParamError("joystick"); \
SDL_UnlockJoysticks(); \
return retval; \
@ -555,7 +555,7 @@ SDL_Joystick *SDL_OpenJoystick(SDL_JoystickID instance_id)
SDL_UnlockJoysticks();
return NULL;
}
joystick->magic = &joystick_magic;
joystick->magic = &SDL_joystick_magic;
joystick->driver = driver;
joystick->instance_id = instance_id;
joystick->attached = SDL_TRUE;
@ -754,7 +754,7 @@ int SDL_SetJoystickVirtualHat(SDL_Joystick *joystick, int hat, Uint8 value)
SDL_bool SDL_IsJoystickValid(SDL_Joystick *joystick)
{
SDL_AssertJoysticksLocked();
return (joystick && joystick->magic == &joystick_magic);
return (joystick && joystick->magic == &SDL_joystick_magic);
}
SDL_bool SDL_PrivateJoystickGetAutoGamepadMapping(SDL_JoystickID instance_id, SDL_GamepadMapping *out)

View File

@ -32,6 +32,7 @@ extern "C" {
#endif
struct SDL_JoystickDriver;
extern char SDL_joystick_magic;
/* Initialization and shutdown functions */
extern int SDL_InitJoysticks(void);

View File

@ -1645,6 +1645,7 @@ static SDL_bool LINUX_JoystickGetGamepadMapping(int device_index, SDL_GamepadMap
/* We temporarily open the device to check how it's configured. Make
a fake SDL_Joystick object to do so. */
joystick = (SDL_Joystick *)SDL_calloc(sizeof(*joystick), 1);
joystick->magic = &SDL_joystick_magic;
if (joystick == NULL) {
SDL_OutOfMemory();
return SDL_FALSE;