Просмотр исходного кода

Fixed HIDAPI hotplug detection in applications that don't initialize video

Sam Lantinga 3 недель назад
Родитель
Сommit
eaeca340f3
3 измененных файлов с 9 добавлено и 1 удалено
  1. 5 0
      src/SDL.c
  2. 3 0
      src/SDL_internal.h
  3. 1 1
      src/hidapi/SDL_hidapi.c

+ 5 - 0
src/SDL.c

@@ -280,6 +280,11 @@ bool SDL_IsMainThread(void)
     return true;
     return true;
 }
 }
 
 
+bool SDL_IsVideoThread(void)
+{
+    return (SDL_GetCurrentThreadID() == SDL_VideoThreadID);
+}
+
 // Initialize all the subsystems that require initialization before threads start
 // Initialize all the subsystems that require initialization before threads start
 void SDL_InitMainThread(void)
 void SDL_InitMainThread(void)
 {
 {

+ 3 - 0
src/SDL_internal.h

@@ -307,6 +307,9 @@ extern SDL_NORETURN void SDL_ExitProcess(int exitcode);
 // Do any initialization that needs to happen before threads are started
 // Do any initialization that needs to happen before threads are started
 extern void SDL_InitMainThread(void);
 extern void SDL_InitMainThread(void);
 
 
+// Return true if this thread has initialized video
+extern bool SDL_IsVideoThread(void);
+
 /* The internal implementations of these functions have up to nanosecond precision.
 /* The internal implementations of these functions have up to nanosecond precision.
    We can expose these functions as part of the API if we want to later.
    We can expose these functions as part of the API if we want to later.
 */
 */

+ 1 - 1
src/hidapi/SDL_hidapi.c

@@ -388,7 +388,7 @@ static void HIDAPI_UpdateDiscovery(void)
     }
     }
 
 
 #if defined(SDL_PLATFORM_WIN32) || defined(SDL_PLATFORM_WINGDK)
 #if defined(SDL_PLATFORM_WIN32) || defined(SDL_PLATFORM_WINGDK)
-    if (SDL_IsMainThread()) {
+    if (SDL_IsVideoThread()) {
         // just let the usual SDL_PumpEvents loop dispatch these, fixing bug 2998. --ryan.
         // just let the usual SDL_PumpEvents loop dispatch these, fixing bug 2998. --ryan.
     } else {
     } else {
         // We'll only get messages on the same thread that created the window
         // We'll only get messages on the same thread that created the window