From c881cd2d1452dc6ad87a570db76139a0c6105132 Mon Sep 17 00:00:00 2001 From: RhavoX Date: Mon, 20 Jun 2022 19:01:55 +0200 Subject: [PATCH] Fix doubling of detected gamepads on program start (#3398) * Fix doubling of detected gamepads (sometimes the connected event is fired when the app starts even though the pad was connected for some time now). The fix rejects the gamepad if one with the same ID is already present. * Fixed review findings --- Ryujinx.Input.SDL2/SDL2GamepadDriver.cs | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/Ryujinx.Input.SDL2/SDL2GamepadDriver.cs b/Ryujinx.Input.SDL2/SDL2GamepadDriver.cs index 927d7fe6e..b20a76b84 100644 --- a/Ryujinx.Input.SDL2/SDL2GamepadDriver.cs +++ b/Ryujinx.Input.SDL2/SDL2GamepadDriver.cs @@ -79,6 +79,13 @@ namespace Ryujinx.Input.SDL2 return; } + // Sometimes a JoyStick connected event fires after the app starts even though it was connected before + // so it is rejected to avoid doubling the entries. + if (_gamepadsIds.Contains(id)) + { + return; + } + if (_gamepadsInstanceIdsMapping.TryAdd(joystickInstanceId, id)) { _gamepadsIds.Add(id);