src/joystick/SDL_gamecontroller.c
changeset 11781 c2f3e4187c9d
parent 11780 874fb85ef7b7
child 11811 5d94cb6b24d3
equal deleted inserted replaced
11780:874fb85ef7b7 11781:c2f3e4187c9d
   909     const char *name;
   909     const char *name;
   910     SDL_JoystickGUID guid;
   910     SDL_JoystickGUID guid;
   911     ControllerMapping_t *mapping;
   911     ControllerMapping_t *mapping;
   912 
   912 
   913     SDL_LockJoysticks();
   913     SDL_LockJoysticks();
       
   914 
       
   915     if ((device_index < 0) || (device_index >= SDL_NumJoysticks())) {
       
   916         SDL_SetError("There are %d joysticks available", SDL_NumJoysticks());
       
   917         SDL_UnlockJoysticks();
       
   918         return (NULL);
       
   919     }
       
   920 
   914     name = SDL_JoystickNameForIndex(device_index);
   921     name = SDL_JoystickNameForIndex(device_index);
   915     guid = SDL_JoystickGetDeviceGUID(device_index);
   922     guid = SDL_JoystickGetDeviceGUID(device_index);
   916     mapping = SDL_PrivateGetControllerMappingForNameAndGUID(name, guid);
   923     mapping = SDL_PrivateGetControllerMappingForNameAndGUID(name, guid);
   917 #if SDL_JOYSTICK_XINPUT
   924 #if SDL_JOYSTICK_XINPUT
   918     if (!mapping && SDL_SYS_IsXInputGamepad_DeviceIndex(device_index)) {
   925     if (!mapping && SDL_SYS_IsXInputGamepad_DeviceIndex(device_index)) {
  1351 {
  1358 {
  1352     SDL_GameController *gamecontroller;
  1359     SDL_GameController *gamecontroller;
  1353     SDL_GameController *gamecontrollerlist;
  1360     SDL_GameController *gamecontrollerlist;
  1354     ControllerMapping_t *pSupportedController = NULL;
  1361     ControllerMapping_t *pSupportedController = NULL;
  1355 
  1362 
       
  1363     SDL_LockJoysticks();
       
  1364 
  1356     if ((device_index < 0) || (device_index >= SDL_NumJoysticks())) {
  1365     if ((device_index < 0) || (device_index >= SDL_NumJoysticks())) {
  1357         SDL_SetError("There are %d joysticks available", SDL_NumJoysticks());
  1366         SDL_SetError("There are %d joysticks available", SDL_NumJoysticks());
       
  1367         SDL_UnlockJoysticks();
  1358         return (NULL);
  1368         return (NULL);
  1359     }
  1369     }
  1360 
       
  1361     SDL_LockJoysticks();
       
  1362 
  1370 
  1363     gamecontrollerlist = SDL_gamecontrollers;
  1371     gamecontrollerlist = SDL_gamecontrollers;
  1364     /* If the controller is already open, return it */
  1372     /* If the controller is already open, return it */
  1365     while (gamecontrollerlist) {
  1373     while (gamecontrollerlist) {
  1366         if (SDL_SYS_GetInstanceIdOfDeviceIndex(device_index) == gamecontrollerlist->joystick->instance_id) {
  1374         if (SDL_SYS_GetInstanceIdOfDeviceIndex(device_index) == gamecontrollerlist->joystick->instance_id) {