Fixed crash in SDL_IsGameController() on Windows if called when a controller is being removed

This commit is contained in:
Sam Lantinga 2017-10-09 11:45:15 -07:00
parent b120fb879a
commit 2657dfae49

View File

@ -906,14 +906,20 @@ static ControllerMapping_t *SDL_PrivateGetControllerMappingForNameAndGUID(const
static ControllerMapping_t *SDL_PrivateGetControllerMapping(int device_index) static ControllerMapping_t *SDL_PrivateGetControllerMapping(int device_index)
{ {
const char *name = SDL_JoystickNameForIndex(device_index); const char *name;
SDL_JoystickGUID guid = SDL_JoystickGetDeviceGUID(device_index); SDL_JoystickGUID guid;
ControllerMapping_t *mapping = SDL_PrivateGetControllerMappingForNameAndGUID(name, 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 SDL_JOYSTICK_XINPUT
if (!mapping && SDL_SYS_IsXInputGamepad_DeviceIndex(device_index)) { if (!mapping && SDL_SYS_IsXInputGamepad_DeviceIndex(device_index)) {
mapping = s_pXInputMapping; mapping = s_pXInputMapping;
} }
#endif #endif
SDL_UnlockJoystickList();
return mapping; return mapping;
} }