From 458938c2ae1f3154c6919fc6e865fdeeb2232e0f Mon Sep 17 00:00:00 2001 From: AL2009man <67606569+AL2009man@users.noreply.github.com> Date: Thu, 6 Mar 2025 20:09:24 -0500 Subject: [PATCH] Attempt to reduce Input leaking To avoid "the Controller is leaking" situation, there's now a Gamepad stat management that should reset Controller state based on connected controller. --- UnleashedRecomp/hid/driver/sdl_hid.cpp | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/UnleashedRecomp/hid/driver/sdl_hid.cpp b/UnleashedRecomp/hid/driver/sdl_hid.cpp index dfb8e37..97df8fb 100644 --- a/UnleashedRecomp/hid/driver/sdl_hid.cpp +++ b/UnleashedRecomp/hid/driver/sdl_hid.cpp @@ -82,6 +82,11 @@ public: return controller; } + void ClearState() + { + memset(&state, 0, sizeof(state)); + } + void PollAxis() { if (!CanPoll()) @@ -184,6 +189,11 @@ inline Controller* FindController(int which) static void SetControllerInputDevice(Controller* controller) { + if (g_activeController && g_activeController != controller) + { + g_activeController->ClearState(); + } + g_activeController = controller; if (App::s_isLoading) @@ -415,3 +425,4 @@ uint32_t hid::GetCapabilities(uint32_t dwUserIndex, XAMINPUT_CAPABILITIES* pCaps return ERROR_SUCCESS; } +