From 071d1e29dd4f80605932f320aa2e05fda383944c Mon Sep 17 00:00:00 2001 From: Sam Lantinga Date: Tue, 13 Jun 2023 10:05:19 -0700 Subject: [PATCH] Fixed joystick vendor detection in Linux automatic gamepad mapping --- src/joystick/SDL_joystick.c | 8 ++++---- src/joystick/SDL_joystick_c.h | 1 + src/joystick/linux/SDL_sysjoystick.c | 1 + 3 files changed, 6 insertions(+), 4 deletions(-) diff --git a/src/joystick/SDL_joystick.c b/src/joystick/SDL_joystick.c index 0a1e65b5f..59a9bbdda 100644 --- a/src/joystick/SDL_joystick.c +++ b/src/joystick/SDL_joystick.c @@ -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) diff --git a/src/joystick/SDL_joystick_c.h b/src/joystick/SDL_joystick_c.h index 0eb584887..46de50d0a 100644 --- a/src/joystick/SDL_joystick_c.h +++ b/src/joystick/SDL_joystick_c.h @@ -32,6 +32,7 @@ extern "C" { #endif struct SDL_JoystickDriver; +extern char SDL_joystick_magic; /* Initialization and shutdown functions */ extern int SDL_InitJoysticks(void); diff --git a/src/joystick/linux/SDL_sysjoystick.c b/src/joystick/linux/SDL_sysjoystick.c index a2e20ce4f..b41ee40d0 100644 --- a/src/joystick/linux/SDL_sysjoystick.c +++ b/src/joystick/linux/SDL_sysjoystick.c @@ -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;