From ccbb02a04bd776fcc31c51fe993521e7078fe244 Mon Sep 17 00:00:00 2001 From: chrg6 Date: Sun, 8 Nov 2026 09:14:33 -0500 Subject: [PATCH] Empty SDL's event queue after each gamepad update on Windows. Nothing reads SDL's events there (the window is our own), yet every axis and button change of a gamepad was queued until SDL's cap of about 65,000 events, several MB, after which each further event failed and set SDL's error text, which later log lines report. The gamepad state the input code reads does not come from the queue. Co-Authored-By: Claude Opus 5.5 --- runtime/input.c | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/runtime/input.c b/runtime/input.c index 1305ee64..7f103f24 100644 --- a/runtime/input.c +++ b/runtime/input.c @@ -623,6 +623,12 @@ static int pad_physical(uint8_t pd[PAD_COUNT]) { // every RESCAN_MS, not only without a gamepad: a second controller, or one that wakes up after the start, is found if (plat_now_ns() / 1000000u >= next_scan) { next_scan = plat_now_ns() / 1000000u + RESCAN_MS; scan_pads(); } SDL_UpdateGamepads(); +#ifdef _WIN32 + // The Windows window is our own (gfx_window_win.c), so nothing reads SDL's event queue, yet every axis and button + // change of a gamepad is queued there: at SDL's cap (about 65,000 events, several MB) each further one fails and + // sets SDL's error text. The state the calls below read does not come from the queue. + SDL_FlushEvents(SDL_EVENT_FIRST, SDL_EVENT_LAST); +#endif pad_follow(); if (!pad || !SDL_GamepadConnected(pad)) return 0; for (int p = PAD_SOUTH; p < PAD_ZL; p++) pd[p] = SDL_GetGamepadButton(pad, pad_sdl[p]);