SDLInputSource: Deduplicate controllers based on instance ID

This commit is contained in:
Stenzek 2023-09-07 13:12:25 +10:00 committed by Connor McLaughlin
parent 217999912a
commit f46c3b36cc
1 changed files with 14 additions and 0 deletions

View File

@ -592,6 +592,20 @@ bool SDLInputSource::OpenDevice(int index, bool is_gamecontroller)
const int joystick_id = SDL_JoystickInstanceID(joystick);
int player_id = gcontroller ? SDL_GameControllerGetPlayerIndex(gcontroller) : SDL_JoystickGetPlayerIndex(joystick);
for (auto it = m_controllers.begin(); it != m_controllers.end(); ++it)
{
if (it->joystick_id == joystick_id)
{
Console.Error("(SDLInputSource) Controller %d, instance %d, player %d already connected, ignoring.", index, joystick_id, player_id);
if (gcontroller)
SDL_GameControllerClose(gcontroller);
else
SDL_JoystickClose(joystick);
return false;
}
}
if (player_id < 0 || GetControllerDataForPlayerId(player_id) != m_controllers.end())
{
const int free_player_id = GetFreePlayerId();