Fixed joystick vendor detection in Linux automatic gamepad mapping (cherry picked from commit 071d1e29dd4f80605932f320aa2e05fda383944c)
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59
diff --git a/src/joystick/SDL_joystick.c b/src/joystick/SDL_joystick.c
index 8bdf952..5e46bc1 100644
--- a/src/joystick/SDL_joystick.c
+++ b/src/joystick/SDL_joystick.c
@@ -123,10 +123,10 @@ static SDL_atomic_t SDL_next_joystick_instance_id SDL_GUARDED_BY(SDL_joystick_lo
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; \
@@ -514,7 +514,7 @@ SDL_Joystick *SDL_JoystickOpen(int device_index)
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;
@@ -723,7 +723,7 @@ int SDL_JoystickSetVirtualHat(SDL_Joystick *joystick, int hat, Uint8 value)
SDL_bool SDL_PrivateJoystickValid(SDL_Joystick *joystick)
{
SDL_AssertJoysticksLocked();
- return (joystick && joystick->magic == &joystick_magic);
+ return (joystick && joystick->magic == &SDL_joystick_magic);
}
SDL_bool SDL_PrivateJoystickGetAutoGamepadMapping(int device_index, SDL_GamepadMapping *out)
diff --git a/src/joystick/SDL_joystick_c.h b/src/joystick/SDL_joystick_c.h
index 48f5563..484746d 100644
--- a/src/joystick/SDL_joystick_c.h
+++ b/src/joystick/SDL_joystick_c.h
@@ -34,6 +34,7 @@ extern "C" {
#endif
struct _SDL_JoystickDriver;
+extern char SDL_joystick_magic;
/* Initialization and shutdown functions */
extern int SDL_JoystickInit(void);
diff --git a/src/joystick/linux/SDL_sysjoystick.c b/src/joystick/linux/SDL_sysjoystick.c
index 6d1c90d..df73ced 100644
--- a/src/joystick/linux/SDL_sysjoystick.c
+++ b/src/joystick/linux/SDL_sysjoystick.c
@@ -1708,6 +1708,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;