From aee6734cffb5666bdd04115c60db6257bcd5401e Mon Sep 17 00:00:00 2001 From: Dino <84743074+LeapersEdge@users.noreply.github.com> Date: Fri, 26 Dec 2025 20:46:09 +0100 Subject: [PATCH] fix: set correct default axes for gamepads that are not connected (inside rcore_desktop_glfw.c) (#5444) * fix: set correct default axes for gamepads that are not connected `glfwGetGamepadState` will set all gamepad state variables to 0.0 if required gamepad is not connected, but `RecordAutomationEvent()` inside rcore.c expects trigger axes to be -1.0f when gamepad is not connected. Since SDL and RGFW return -1.0f in such case, this change is aligning it with them * updated comment in rcore_desktop_glfw.c --- src/platforms/rcore_desktop_glfw.c | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/src/platforms/rcore_desktop_glfw.c b/src/platforms/rcore_desktop_glfw.c index 471050839..368dd5de8 100644 --- a/src/platforms/rcore_desktop_glfw.c +++ b/src/platforms/rcore_desktop_glfw.c @@ -1266,8 +1266,14 @@ void PollInputEvents(void) // Get current gamepad state // NOTE: There is no callback available, so we get it manually GLFWgamepadstate state = { 0 }; - glfwGetGamepadState(i, &state); // This remapps all gamepads so they have their buttons mapped like an xbox controller - + int isGamepadConnected = glfwGetGamepadState(i, &state); // This remapps all gamepads so they have their buttons mapped like an xbox controller + if (!isGamepadConnected) + { + // setting axes to expected resting value instead of GLFW's 0.0f default when gamepad isnt connected + state.axes[GAMEPAD_AXIS_LEFT_TRIGGER] = -1.0f; + state.axes[GAMEPAD_AXIS_RIGHT_TRIGGER] = -1.0f; + } + const unsigned char *buttons = state.buttons; for (int k = 0; (buttons != NULL) && (k < MAX_GAMEPAD_BUTTONS); k++)