From d847b71c86e7c6e9d50c227f1b55e776ad3470ce Mon Sep 17 00:00:00 2001 From: Cameron Gutman Date: Sun, 18 Nov 2018 12:05:17 -0800 Subject: [PATCH] Fix host virtual gamepads being reconnected during stream startup and causing issues with multiple controllers. Fixes #108 --- app/streaming/input.cpp | 16 +++++++--------- 1 file changed, 7 insertions(+), 9 deletions(-) diff --git a/app/streaming/input.cpp b/app/streaming/input.cpp index d8ca69dd..50f75490 100644 --- a/app/streaming/input.cpp +++ b/app/streaming/input.cpp @@ -69,14 +69,10 @@ SdlInputHandler::SdlInputHandler(StreamingPreferences& prefs, NvComputer*, int s MappingManager mappingManager; mappingManager.applyMappings(); - if (!m_MultiController) { - // Player 1 is always present in non-MC mode - m_GamepadMask = 0x1; - } - else { - // Otherwise, detect gamepads on the fly - m_GamepadMask = 0; - } + // Initialize the gamepad mask with currently attached gamepads to avoid + // causing gamepads to unexpectedly disappear and reappear on the host + // during stream startup as we detect currently attached gamepads one at a time. + m_GamepadMask = getAttachedGamepadMask(); SDL_zero(m_GamepadState); SDL_zero(m_TouchDownEvent); @@ -700,7 +696,9 @@ void SdlInputHandler::handleControllerDeviceEvent(SDL_ControllerDeviceEvent* eve // Add this gamepad to the gamepad mask if (m_MultiController) { - SDL_assert(!(m_GamepadMask & (1 << state->index))); + // NB: Don't assert that it's unset here because we will already + // have the mask set for initially attached gamepads to avoid confusing + // apps running on the host. m_GamepadMask |= (1 << state->index); } else {