Skip to content

Commit

Permalink
Fix incorrect player index when assigning a joystick the same index t…
Browse files Browse the repository at this point in the history
…wice

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.
  • Loading branch information
cgutman committed Mar 8, 2020
1 parent e152a3c commit 165ccaa
Showing 1 changed file with 3 additions and 0 deletions.
3 changes: 3 additions & 0 deletions src/joystick/SDL_joystick.c
Expand Up @@ -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;
Expand Down

0 comments on commit 165ccaa

Please sign in to comment.