src/joystick/SDL_gamecontroller.c
changeset 11781 c2f3e4187c9d
parent 11780 874fb85ef7b7
child 11811 5d94cb6b24d3
     1.1 --- a/src/joystick/SDL_gamecontroller.c	Sat Dec 16 10:40:47 2017 -0800
     1.2 +++ b/src/joystick/SDL_gamecontroller.c	Tue Dec 19 10:48:29 2017 -0800
     1.3 @@ -911,6 +911,13 @@
     1.4      ControllerMapping_t *mapping;
     1.5  
     1.6      SDL_LockJoysticks();
     1.7 +
     1.8 +    if ((device_index < 0) || (device_index >= SDL_NumJoysticks())) {
     1.9 +        SDL_SetError("There are %d joysticks available", SDL_NumJoysticks());
    1.10 +        SDL_UnlockJoysticks();
    1.11 +        return (NULL);
    1.12 +    }
    1.13 +
    1.14      name = SDL_JoystickNameForIndex(device_index);
    1.15      guid = SDL_JoystickGetDeviceGUID(device_index);
    1.16      mapping = SDL_PrivateGetControllerMappingForNameAndGUID(name, guid);
    1.17 @@ -1353,13 +1360,14 @@
    1.18      SDL_GameController *gamecontrollerlist;
    1.19      ControllerMapping_t *pSupportedController = NULL;
    1.20  
    1.21 +    SDL_LockJoysticks();
    1.22 +
    1.23      if ((device_index < 0) || (device_index >= SDL_NumJoysticks())) {
    1.24          SDL_SetError("There are %d joysticks available", SDL_NumJoysticks());
    1.25 +        SDL_UnlockJoysticks();
    1.26          return (NULL);
    1.27      }
    1.28  
    1.29 -    SDL_LockJoysticks();
    1.30 -
    1.31      gamecontrollerlist = SDL_gamecontrollers;
    1.32      /* If the controller is already open, return it */
    1.33      while (gamecontrollerlist) {