Fixed joystick vendor detection in Linux automatic gamepad mapping

(cherry picked from commit 071d1e29dd4f80605932f320aa2e05fda383944c)
This commit is contained in:
Sam Lantinga 2023-06-13 10:05:19 -07:00
parent 36ff6327b0
commit 7db23f4ef1
3 changed files with 6 additions and 4 deletions

View file

@ -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 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_JoystickID *SDL_joystick_players SDL_GUARDED_BY(SDL_joystick_lock) = NULL;
static SDL_bool SDL_joystick_allows_background_events = SDL_FALSE; static SDL_bool SDL_joystick_allows_background_events = SDL_FALSE;
static char joystick_magic; char SDL_joystick_magic;
#define CHECK_JOYSTICK_MAGIC(joystick, retval) \ #define CHECK_JOYSTICK_MAGIC(joystick, retval) \
if (!joystick || joystick->magic != &joystick_magic) { \ if (!joystick || joystick->magic != &SDL_joystick_magic) { \
SDL_InvalidParamError("joystick"); \ SDL_InvalidParamError("joystick"); \
SDL_UnlockJoysticks(); \ SDL_UnlockJoysticks(); \
return retval; \ return retval; \
@ -514,7 +514,7 @@ SDL_Joystick *SDL_JoystickOpen(int device_index)
SDL_UnlockJoysticks(); SDL_UnlockJoysticks();
return NULL; return NULL;
} }
joystick->magic = &joystick_magic; joystick->magic = &SDL_joystick_magic;
joystick->driver = driver; joystick->driver = driver;
joystick->instance_id = instance_id; joystick->instance_id = instance_id;
joystick->attached = SDL_TRUE; 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_bool SDL_PrivateJoystickValid(SDL_Joystick *joystick)
{ {
SDL_AssertJoysticksLocked(); 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) SDL_bool SDL_PrivateJoystickGetAutoGamepadMapping(int device_index, SDL_GamepadMapping *out)

View file

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

View file

@ -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 /* We temporarily open the device to check how it's configured. Make
a fake SDL_Joystick object to do so. */ a fake SDL_Joystick object to do so. */
joystick = (SDL_Joystick *)SDL_calloc(sizeof(*joystick), 1); joystick = (SDL_Joystick *)SDL_calloc(sizeof(*joystick), 1);
joystick->magic = &SDL_joystick_magic;
if (joystick == NULL) { if (joystick == NULL) {
SDL_OutOfMemory(); SDL_OutOfMemory();
return SDL_FALSE; return SDL_FALSE;