From e9dbf45f131aab77d8dbf59bec65d8ea796461c0 Mon Sep 17 00:00:00 2001 From: Michael Date: Tue, 10 Oct 2023 19:19:28 -0400 Subject: [PATCH] Move axis count update out of GamepadThread - race condition --- src/rcore_drm.c | 12 +++++------- 1 file changed, 5 insertions(+), 7 deletions(-) diff --git a/src/rcore_drm.c b/src/rcore_drm.c index 03ed5888c..cfef6a69f 100644 --- a/src/rcore_drm.c +++ b/src/rcore_drm.c @@ -1948,6 +1948,11 @@ static void InitGamepad(void) } ioctl(platform.gamepadStreamFd[i], JSIOCGNAME(64), &CORE.Input.Gamepad.name[i]); + + + int axisCount = 0; + if (CORE.Input.Gamepad.ready[i]) ioctl(platform.gamepadStreamFd[i], JSIOCGAXES, &axisCount); + CORE.Input.Gamepad.axisCount = axisCount; } } } @@ -1969,17 +1974,10 @@ static void *GamepadThread(void *arg) // Read gamepad event struct js_event gamepadEvent = { 0 }; - int axisCount = 0; - while (!CORE.Window.shouldClose) { for (int i = 0; i < MAX_GAMEPADS; i++) { - // Update the axis count for each gamepad. - axisCount = 0; - if (CORE.Input.Gamepad.ready[i]) ioctl(platform.gamepadStreamFd[i], JSIOCGAXES, &axisCount); - CORE.Input.Gamepad.axisCount = axisCount; - if (read(platform.gamepadStreamFd[i], &gamepadEvent, sizeof(struct js_event)) == (int)sizeof(struct js_event)) { gamepadEvent.type &= ~JS_EVENT_INIT; // Ignore synthetic events