From 165ccaa85b8a9abaf38ad92e147a3710a0d7d0de Mon Sep 17 00:00:00 2001 From: Cameron Gutman Date: Sat, 7 Mar 2020 17:20:04 -0800 Subject: [PATCH] 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 | 3 +++ 1 file changed, 3 insertions(+) diff --git a/src/joystick/SDL_joystick.c b/src/joystick/SDL_joystick.c index 406d148e332ce..929f9582b58da 100644 --- a/src/joystick/SDL_joystick.c +++ b/src/joystick/SDL_joystick.c @@ -160,6 +160,9 @@ SDL_SetJoystickIDForPlayerIndex(int player_index, SDL_JoystickID instance_id) SDL_joystick_players = new_players; SDL_memset(&SDL_joystick_players[SDL_joystick_player_count], 0xFF, (player_index - SDL_joystick_player_count + 1) * sizeof(SDL_joystick_players[0])); SDL_joystick_player_count = player_index + 1; + } else if (SDL_joystick_players[player_index] == instance_id) { + /* Joystick is already assigned the requested player index */ + return SDL_TRUE; } SDL_joystick_players[player_index] = instance_id;