Fix incorrect player index when assigning a joystick the same index twice
authorCameron Gutman <aicommander@gmail.com>
Sat, 07 Mar 2020 17:20:04 -0800
changeset 1359536aabb2051e9
parent 13594 9b5e16574ea9
child 13596 501950e51321
Fix incorrect player index when assigning a joystick the same index twice

Prior to this fix, we would hit the existing_instance >= 0 case and move the joystick
again to a different index than the one requested by the caller. It also breaks the assumption
that a SDL_JoystickID is only present in SDL_joystick_players at one location.
src/joystick/SDL_joystick.c
     1.1 --- a/src/joystick/SDL_joystick.c	Sat Mar 07 13:59:42 2020 -0800
     1.2 +++ b/src/joystick/SDL_joystick.c	Sat Mar 07 17:20:04 2020 -0800
     1.3 @@ -160,6 +160,9 @@
     1.4          SDL_joystick_players = new_players;
     1.5          SDL_memset(&SDL_joystick_players[SDL_joystick_player_count], 0xFF, (player_index - SDL_joystick_player_count + 1) * sizeof(SDL_joystick_players[0]));
     1.6          SDL_joystick_player_count = player_index + 1;
     1.7 +    } else if (SDL_joystick_players[player_index] == instance_id) {
     1.8 +        /* Joystick is already assigned the requested player index */
     1.9 +        return SDL_TRUE;
    1.10      }
    1.11  
    1.12      SDL_joystick_players[player_index] = instance_id;