From ce171b2e171ca3bcb6e4c6f7d724b9edf7a0e34f Mon Sep 17 00:00:00 2001 From: Leon Styhre Date: Sat, 7 Oct 2023 14:03:17 +0200 Subject: [PATCH] Improved resilience to buggy controller drivers which could previously crash the application --- es-core/src/InputManager.cpp | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/es-core/src/InputManager.cpp b/es-core/src/InputManager.cpp index 9a0bc24c1..ef18b33dc 100644 --- a/es-core/src/InputManager.cpp +++ b/es-core/src/InputManager.cpp @@ -641,6 +641,16 @@ void InputManager::addControllerByDeviceIndex(Window* window, int deviceIndex) SDL_JoystickGetGUIDString(SDL_JoystickGetGUID(joy), &guid[0], 64); guid.erase(guid.find('\0')); + if (guid.substr(0, 32) == "00000000000000000000000000000000") { + // This can occur if there are SDL bugs or controller driver bugs. + LOG(LogWarning) + << "Attempted to add an invalid controller entry with zero GUID, buggy drivers?"; + SDL_GameControllerClose(controller); + mControllers.erase(mControllers.find(joyID)); + mJoysticks.erase(mJoysticks.find(joyID)); + return; + } + mInputConfigs[joyID] = std::make_unique(joyID, SDL_GameControllerName(mControllers[joyID]), guid);