From 5397e8ae1a270337dd4a6eaf368c9c87174e4ab9 Mon Sep 17 00:00:00 2001 From: Cameron Gutman Date: Tue, 12 Feb 2019 22:04:05 -0800 Subject: [PATCH] Don't use SDL_GameControllerGetPlayerIndex() because the indexes may be non-contiguous (and wrong) on XInput --- app/streaming/input.cpp | 16 +++++----------- 1 file changed, 5 insertions(+), 11 deletions(-) diff --git a/app/streaming/input.cpp b/app/streaming/input.cpp index 7571540f..4a6c885a 100644 --- a/app/streaming/input.cpp +++ b/app/streaming/input.cpp @@ -682,17 +682,12 @@ void SdlInputHandler::handleControllerDeviceEvent(SDL_ControllerDeviceEvent* eve return; } -#if SDL_VERSION_ATLEAST(2, 0, 9) - // Determine this player's preferred index - i = SDL_GameControllerGetPlayerIndex(controller); - if (i < 0 || i >= MAX_GAMEPADS || m_GamepadState[i].controller != NULL) { - // If the player index is unavailable or invalid, start searching from 0 - i = 0; - } -#else - // SDL 2.0.8 and earlier has no player number hints + // We used to use SDL_GameControllerGetPlayerIndex() here but that + // can lead to strange issues due to bugs in Windows where an Xbox + // controller will join as player 2, even though no player 1 controller + // is connected at all. This pretty much screws any attempt to use + // the gamepad in single player games, so just assign them in order from 0. i = 0; -#endif for (; i < MAX_GAMEPADS; i++) { if (m_GamepadState[i].controller == NULL) { @@ -996,7 +991,6 @@ int SdlInputHandler::getAttachedGamepadMask() return 0x1; } - // TODO: Use SDL_GameControllerGetPlayerIndex() for accurate indexes? count = mask = 0; for (int i = 0; i < SDL_NumJoysticks(); i++) { if (SDL_IsGameController(i)) {