From 2657dfae4966ba710e9b5ed5d396ddec47dd57a9 Mon Sep 17 00:00:00 2001 From: Sam Lantinga Date: Mon, 9 Oct 2017 11:45:15 -0700 Subject: [PATCH] Fixed crash in SDL_IsGameController() on Windows if called when a controller is being removed --- src/joystick/SDL_gamecontroller.c | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/src/joystick/SDL_gamecontroller.c b/src/joystick/SDL_gamecontroller.c index 1483c98a8..0802c88c7 100644 --- a/src/joystick/SDL_gamecontroller.c +++ b/src/joystick/SDL_gamecontroller.c @@ -906,14 +906,20 @@ static ControllerMapping_t *SDL_PrivateGetControllerMappingForNameAndGUID(const static ControllerMapping_t *SDL_PrivateGetControllerMapping(int device_index) { - const char *name = SDL_JoystickNameForIndex(device_index); - SDL_JoystickGUID guid = SDL_JoystickGetDeviceGUID(device_index); - ControllerMapping_t *mapping = SDL_PrivateGetControllerMappingForNameAndGUID(name, guid); + const char *name; + SDL_JoystickGUID guid; + ControllerMapping_t *mapping; + + SDL_LockJoystickList(); + name = SDL_JoystickNameForIndex(device_index); + guid = SDL_JoystickGetDeviceGUID(device_index); + mapping = SDL_PrivateGetControllerMappingForNameAndGUID(name, guid); #if SDL_JOYSTICK_XINPUT if (!mapping && SDL_SYS_IsXInputGamepad_DeviceIndex(device_index)) { mapping = s_pXInputMapping; } #endif + SDL_UnlockJoystickList(); return mapping; }