From 8adc0f98837db84fd24f17c339e59dcf36a17156 Mon Sep 17 00:00:00 2001
From: Sam Lantinga <[EMAIL REDACTED]>
Date: Thu, 22 Oct 2026 11:13:43 -0700
Subject: [PATCH] fix SDL_joystick thread busy-looping on Windows while a
device change is pending
SDL_WaitForDeviceNotification() returned without calling GetMessage() whenever a device change was pending, and it stays pending until the next WINDOWS_JoystickDetect(), so the thread spun for 100-200ms after every hotplug.
---
src/joystick/windows/SDL_windowsjoystick.c | 4 +++-
1 file changed, 3 insertions(+), 1 deletion(-)
diff --git a/src/joystick/windows/SDL_windowsjoystick.c b/src/joystick/windows/SDL_windowsjoystick.c
index 6537cb518786a..0ba3746e552fd 100644
--- a/src/joystick/windows/SDL_windowsjoystick.c
+++ b/src/joystick/windows/SDL_windowsjoystick.c
@@ -200,7 +200,9 @@ static bool SDL_WaitForDeviceNotification(SDL_DeviceNotificationData *data, SDL_
}
SDL_UnlockMutex(mutex);
- while (lastret > 0 && !WindowsDeviceChanged()) {
+ // Pump messages until we're told to quit. Device changes are picked up by WINDOWS_JoystickDetect(),
+ // so returning while one is pending would just spin until the next detect.
+ while (lastret > 0) {
lastret = GetMessage(&msg, NULL, 0, 0); // WM_QUIT causes return value of 0
if (lastret > 0) {
TranslateMessage(&msg);