Skip to content

Commit

Permalink
Move axis count update out of GamepadThread - race condition
Browse files Browse the repository at this point in the history
  • Loading branch information
michaelfiber committed Oct 10, 2023
1 parent 3028324 commit e9dbf45
Showing 1 changed file with 5 additions and 7 deletions.
12 changes: 5 additions & 7 deletions src/rcore_drm.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
}
}
Expand All @@ -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
Expand Down

0 comments on commit e9dbf45

Please sign in to comment.