Skip to content

Commit eaeca34

Browse files
committed
Fixed HIDAPI hotplug detection in applications that don't initialize video
1 parent d3f9899 commit eaeca34

File tree

3 files changed

+9
-1
lines changed

3 files changed

+9
-1
lines changed

src/SDL.c

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -280,6 +280,11 @@ bool SDL_IsMainThread(void)
280280
return true;
281281
}
282282

283+
bool SDL_IsVideoThread(void)
284+
{
285+
return (SDL_GetCurrentThreadID() == SDL_VideoThreadID);
286+
}
287+
283288
// Initialize all the subsystems that require initialization before threads start
284289
void SDL_InitMainThread(void)
285290
{

src/SDL_internal.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -307,6 +307,9 @@ extern SDL_NORETURN void SDL_ExitProcess(int exitcode);
307307
// Do any initialization that needs to happen before threads are started
308308
extern void SDL_InitMainThread(void);
309309

310+
// Return true if this thread has initialized video
311+
extern bool SDL_IsVideoThread(void);
312+
310313
/* The internal implementations of these functions have up to nanosecond precision.
311314
We can expose these functions as part of the API if we want to later.
312315
*/

src/hidapi/SDL_hidapi.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -388,7 +388,7 @@ static void HIDAPI_UpdateDiscovery(void)
388388
}
389389

390390
#if defined(SDL_PLATFORM_WIN32) || defined(SDL_PLATFORM_WINGDK)
391-
if (SDL_IsMainThread()) {
391+
if (SDL_IsVideoThread()) {
392392
// just let the usual SDL_PumpEvents loop dispatch these, fixing bug 2998. --ryan.
393393
} else {
394394
// We'll only get messages on the same thread that created the window

0 commit comments

Comments
 (0)