diff --git a/app/gui/sdlgamepadkeynavigation.cpp b/app/gui/sdlgamepadkeynavigation.cpp index c10ae4dd4..88693b87e 100644 --- a/app/gui/sdlgamepadkeynavigation.cpp +++ b/app/gui/sdlgamepadkeynavigation.cpp @@ -55,7 +55,8 @@ void SdlGamepadKeyNavigation::enable() SDL_FlushEvent(SDL_CONTROLLERDEVICEADDED); // Open all currently attached game controllers - for (int i = 0; i < SDL_NumJoysticks(); i++) { + int numJoysticks = SDL_NumJoysticks(); + for (int i = 0; i < numJoysticks; i++) { if (SDL_IsGameController(i)) { SDL_GameController* gc = SDL_GameControllerOpen(i); if (gc != nullptr) { @@ -289,7 +290,8 @@ int SdlGamepadKeyNavigation::getConnectedGamepads() Q_ASSERT(m_Enabled); int count = 0; - for (int i = 0; i < SDL_NumJoysticks(); i++) { + int numJoysticks = SDL_NumJoysticks(); + for (int i = 0; i < numJoysticks; i++) { if (SDL_IsGameController(i)) { count++; } diff --git a/app/streaming/input/gamepad.cpp b/app/streaming/input/gamepad.cpp index 502511f80..131ec1931 100644 --- a/app/streaming/input/gamepad.cpp +++ b/app/streaming/input/gamepad.cpp @@ -913,7 +913,8 @@ QString SdlInputHandler::getUnmappedGamepads() MappingManager mappingManager; mappingManager.applyMappings(); - for (int i = 0; i < SDL_NumJoysticks(); i++) { + int numJoysticks = SDL_NumJoysticks(); + for (int i = 0; i < numJoysticks; i++) { if (!SDL_IsGameController(i)) { char guidStr[33]; SDL_JoystickGetGUIDString(SDL_JoystickGetDeviceGUID(i), @@ -973,7 +974,8 @@ int SdlInputHandler::getAttachedGamepadMask() } count = mask = 0; - for (int i = 0; i < SDL_NumJoysticks(); i++) { + int numJoysticks = SDL_NumJoysticks(); + for (int i = 0; i < numJoysticks; i++) { if (SDL_IsGameController(i)) { char guidStr[33]; SDL_JoystickGetGUIDString(SDL_JoystickGetDeviceGUID(i),