From d3f9899df5acf7cc480625f3f684ca8ee33b8c35 Mon Sep 17 00:00:00 2001 From: Sam Lantinga Date: Wed, 11 Feb 2026 09:02:46 -0800 Subject: [PATCH] Fixed HIDAPI hotplug detection when initializing gamepads off the main thread --- src/hidapi/SDL_hidapi.c | 20 +++++++++++--------- 1 file changed, 11 insertions(+), 9 deletions(-) diff --git a/src/hidapi/SDL_hidapi.c b/src/hidapi/SDL_hidapi.c index 5331939952..f3de6b344b 100644 --- a/src/hidapi/SDL_hidapi.c +++ b/src/hidapi/SDL_hidapi.c @@ -388,18 +388,20 @@ static void HIDAPI_UpdateDiscovery(void) } #if defined(SDL_PLATFORM_WIN32) || defined(SDL_PLATFORM_WINGDK) -#if 0 // just let the usual SDL_PumpEvents loop dispatch these, fixing bug 4286. --ryan. - // We'll only get messages on the same thread that created the window - if (SDL_GetCurrentThreadID() == SDL_HIDAPI_discovery.m_nThreadID) { - MSG msg; - while (PeekMessage(&msg, SDL_HIDAPI_discovery.m_hwndMsg, 0, 0, PM_NOREMOVE)) { - if (GetMessageA(&msg, SDL_HIDAPI_discovery.m_hwndMsg, 0, 0) != 0) { - TranslateMessage(&msg); - DispatchMessage(&msg); + if (SDL_IsMainThread()) { + // just let the usual SDL_PumpEvents loop dispatch these, fixing bug 2998. --ryan. + } else { + // We'll only get messages on the same thread that created the window + if (SDL_GetCurrentThreadID() == SDL_HIDAPI_discovery.m_nThreadID) { + MSG msg; + while (PeekMessage(&msg, SDL_HIDAPI_discovery.m_hwndMsg, 0, 0, PM_NOREMOVE)) { + if (GetMessageA(&msg, SDL_HIDAPI_discovery.m_hwndMsg, 0, 0) != 0) { + TranslateMessage(&msg); + DispatchMessage(&msg); + } } } } -#endif #endif // defined(SDL_PLATFORM_WIN32) || defined(SDL_PLATFORM_WINGDK) #ifdef SDL_PLATFORM_MACOS