From d657ad5932fc678037aa98a32048e8d70cca6562 Mon Sep 17 00:00:00 2001 From: "Admiral H. Curtiss" Date: Mon, 15 Jan 2024 15:18:38 +0100 Subject: [PATCH] InputCommon/SDL: Check for errors from SDL_JoystickNumButtons(), SDL_JoystickNumAxes(), SDL_JoystickNumHats(). --- .../ControllerInterface/SDL/SDL.cpp | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/Source/Core/InputCommon/ControllerInterface/SDL/SDL.cpp b/Source/Core/InputCommon/ControllerInterface/SDL/SDL.cpp index a8546d10e7..3240a74914 100644 --- a/Source/Core/InputCommon/ControllerInterface/SDL/SDL.cpp +++ b/Source/Core/InputCommon/ControllerInterface/SDL/SDL.cpp @@ -342,8 +342,26 @@ GameController::GameController(SDL_GameController* const gamecontroller, // If a Joystick Button has a GameController equivalent, don't detect it int n_legacy_buttons = SDL_JoystickNumButtons(joystick); + if (n_legacy_buttons < 0) + { + ERROR_LOG_FMT(CONTROLLERINTERFACE, "Error in SDL_JoystickNumButtons(): {}", SDL_GetError()); + n_legacy_buttons = 0; + } + int n_legacy_axes = SDL_JoystickNumAxes(joystick); + if (n_legacy_axes < 0) + { + ERROR_LOG_FMT(CONTROLLERINTERFACE, "Error in SDL_JoystickNumAxes(): {}", SDL_GetError()); + n_legacy_axes = 0; + } + int n_legacy_hats = SDL_JoystickNumHats(joystick); + if (n_legacy_hats < 0) + { + ERROR_LOG_FMT(CONTROLLERINTERFACE, "Error in SDL_JoystickNumHats(): {}", SDL_GetError()); + n_legacy_hats = 0; + } + std::vector is_button_mapped(n_legacy_buttons); std::vector is_axis_mapped(n_legacy_axes); std::vector is_hat_mapped(n_legacy_hats);