Fixed crash in SDL_IsGameController() on Windows if called when a controller is being removed
authorSam Lantinga <slouken@libsdl.org>
Mon, 09 Oct 2017 11:45:15 -0700
changeset 115795789a90f2804
parent 11578 6e8d0e6f4f29
child 11581 49393a9dffe4
Fixed crash in SDL_IsGameController() on Windows if called when a controller is being removed
src/joystick/SDL_gamecontroller.c
     1.1 --- a/src/joystick/SDL_gamecontroller.c	Sun Oct 08 10:59:03 2017 -0700
     1.2 +++ b/src/joystick/SDL_gamecontroller.c	Mon Oct 09 11:45:15 2017 -0700
     1.3 @@ -906,14 +906,20 @@
     1.4  
     1.5  static ControllerMapping_t *SDL_PrivateGetControllerMapping(int device_index)
     1.6  {
     1.7 -    const char *name = SDL_JoystickNameForIndex(device_index);
     1.8 -    SDL_JoystickGUID guid = SDL_JoystickGetDeviceGUID(device_index);
     1.9 -    ControllerMapping_t *mapping = SDL_PrivateGetControllerMappingForNameAndGUID(name, guid);
    1.10 +    const char *name;
    1.11 +    SDL_JoystickGUID guid;
    1.12 +    ControllerMapping_t *mapping;
    1.13 +
    1.14 +    SDL_LockJoystickList();
    1.15 +    name = SDL_JoystickNameForIndex(device_index);
    1.16 +    guid = SDL_JoystickGetDeviceGUID(device_index);
    1.17 +    mapping = SDL_PrivateGetControllerMappingForNameAndGUID(name, guid);
    1.18  #if SDL_JOYSTICK_XINPUT
    1.19      if (!mapping && SDL_SYS_IsXInputGamepad_DeviceIndex(device_index)) {
    1.20          mapping = s_pXInputMapping;
    1.21      }
    1.22  #endif
    1.23 +    SDL_UnlockJoystickList();
    1.24      return mapping;
    1.25  }
    1.26