Free the joystick player index when the joystick is removed
This commit is contained in:
parent
1d321850b6
commit
3a796d6a58
2 changed files with 10 additions and 5 deletions
|
@ -158,8 +158,8 @@ 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;
|
||||
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;
|
||||
}
|
||||
|
||||
SDL_joystick_players[player_index] = instance_id;
|
||||
|
@ -947,6 +947,7 @@ static void UpdateEventsForDeviceRemoval()
|
|||
void SDL_PrivateJoystickRemoved(SDL_JoystickID device_instance)
|
||||
{
|
||||
SDL_Joystick *joystick;
|
||||
int player_index;
|
||||
|
||||
#if !SDL_EVENTS_DISABLED
|
||||
SDL_Event event;
|
||||
|
@ -969,6 +970,13 @@ void SDL_PrivateJoystickRemoved(SDL_JoystickID device_instance)
|
|||
break;
|
||||
}
|
||||
}
|
||||
|
||||
SDL_LockJoysticks();
|
||||
player_index = SDL_GetPlayerIndexForJoystickID(device_instance);
|
||||
if (player_index >= 0) {
|
||||
SDL_joystick_players[player_index] = -1;
|
||||
}
|
||||
SDL_UnlockJoysticks();
|
||||
}
|
||||
|
||||
int
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue