Clear the old player index slot when moving to a new one
authorCameron Gutman <aicommander@gmail.com>
Sat, 07 Mar 2020 19:21:21 -0800
changeset 13596501950e51321
parent 13595 36aabb2051e9
child 13597 178f27cd89a9
Clear the old player index slot when moving to a new one
src/joystick/SDL_joystick.c
     1.1 --- a/src/joystick/SDL_joystick.c	Sat Mar 07 17:20:04 2020 -0800
     1.2 +++ b/src/joystick/SDL_joystick.c	Sat Mar 07 19:21:21 2020 -0800
     1.3 @@ -146,6 +146,7 @@
     1.4      SDL_JoystickID existing_instance = SDL_GetJoystickIDForPlayerIndex(player_index);
     1.5      SDL_JoystickDriver *driver;
     1.6      int device_index;
     1.7 +    int existing_player_index;
     1.8  
     1.9      if (player_index < 0) {
    1.10          return SDL_FALSE;
    1.11 @@ -165,6 +166,12 @@
    1.12          return SDL_TRUE;
    1.13      }
    1.14  
    1.15 +    /* Clear the old player index */
    1.16 +    existing_player_index = SDL_GetPlayerIndexForJoystickID(instance_id);
    1.17 +    if (existing_player_index >= 0) {
    1.18 +        SDL_joystick_players[existing_player_index] = -1;
    1.19 +    }
    1.20 +
    1.21      SDL_joystick_players[player_index] = instance_id;
    1.22  
    1.23      /* Update the driver with the new index */