From e04efa76b309e2119d1724cd102c2631d0b4dba4 Mon Sep 17 00:00:00 2001 From: Rafael Kitover Date: Fri, 29 Nov 2019 03:50:24 +0000 Subject: [PATCH] Release game controller device correctly. #568 A followup on 02520fb6. In wxSDLJoy::Remove(n), which is the only API that needs to release a game controller device from the application, actually call SDL_GameControllerClose(dev) when a device is released. This is used when the input config dialog is launched. First all sticks are closed, and then all available sticks are added for the duration of the dialog. Then they are closed again, and only the configured sticks are open for the game, which is what happens generally. The device ordering is determined by the OS. Signed-off-by: Rafael Kitover --- src/wx/widgets/sdljoy.cpp | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/src/wx/widgets/sdljoy.cpp b/src/wx/widgets/sdljoy.cpp index e55bcb84..612834c8 100644 --- a/src/wx/widgets/sdljoy.cpp +++ b/src/wx/widgets/sdljoy.cpp @@ -147,10 +147,19 @@ void wxSDLJoy::Remove(int8_t joy_n) add_all = false; if (joy_n < 0) { + for (auto joy : joystate) { + if (auto dev = std::get<1>(joy).dev) + SDL_GameControllerClose(dev); + } + joystate.clear(); + return; } + if (auto dev = joystate[joy_n].dev) + SDL_GameControllerClose(dev); + joystate.erase(joy_n); }