From f46c3b36cc417acec85c88c5dd9cda2147ea1c45 Mon Sep 17 00:00:00 2001 From: Stenzek Date: Thu, 7 Sep 2023 13:12:25 +1000 Subject: [PATCH] SDLInputSource: Deduplicate controllers based on instance ID --- pcsx2/Input/SDLInputSource.cpp | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/pcsx2/Input/SDLInputSource.cpp b/pcsx2/Input/SDLInputSource.cpp index 87e8ef8a30775..bc1644d66c3cc 100644 --- a/pcsx2/Input/SDLInputSource.cpp +++ b/pcsx2/Input/SDLInputSource.cpp @@ -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();