mirror of
https://github.com/scp-fs2open/fs2open.github.com.git
synced 2026-11-10 17:46:53 -10:00
Setting SDL_HINT_JOYSTICK_THREAD=1 before SDL_InitSubSystem(SDL_INIT_JOYSTICK) tells SDL2 to run joystick polling and HID device-detection on a dedicated background thread, rather than processing them inline inside SDL_PollEvent on the main thread. Without this hint, every WM_DEVICECHANGE broadcast (which Windows sends when *any* HID device wakes, sleeps, or pulses the USB bus) causes SDL to walk every HID device class via SetupAPI / cfgmgr32 from inside SDL_PollEvent, stalling the frame loop for multiple seconds on machines with many HID peripherals - especially wireless Logitech mice and keyboards that periodically pulse the bus. Diagnosed via ProcMon stack capture on one affected user's machine, with the slow frame's call chain ending in SDL2.dll -> SETUPAPI.dll -> cfgmgr32.dll -> kernel registry queries against HKLM\System\CurrentControlSet\Enum\HID\*. With the hint enabled, that work happens on SDL's own thread and the main thread just dequeues already-collected events.