Parcourir la source

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
RhavoX il y a 3 ans
Parent
commit
c881cd2d14
1 fichiers modifiés avec 7 ajouts et 0 suppressions
  1. 7 0
      Ryujinx.Input.SDL2/SDL2GamepadDriver.cs

+ 7 - 0
Ryujinx.Input.SDL2/SDL2GamepadDriver.cs

@@ -79,6 +79,13 @@ namespace Ryujinx.Input.SDL2
                     return;
                     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))
                 if (_gamepadsInstanceIdsMapping.TryAdd(joystickInstanceId, id))
                 {
                 {
                     _gamepadsIds.Add(id);
                     _gamepadsIds.Add(id);