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

Fall back to polling normally if not operating the win32 message loop

In this condition, we cannot safely wait/wake on events.
Cameron Gutman 4 лет назад
Родитель
Сommit
85b51e6c92
2 измененных файлов с 13 добавлено и 3 удалено
  1. 8 2
      src/events/SDL_events.c
  2. 5 1
      src/video/windows/SDL_windowsevents.c

+ 8 - 2
src/events/SDL_events.c

@@ -817,7 +817,7 @@ SDL_WaitEventTimeout_Device(_THIS, SDL_Window *wakeup_window, SDL_Event * event,
             _this->wakeup_window = NULL;
             if (status <= 0) {
                 /* There is either an error or the timeout is elapsed: return */
-                return 0;
+                return status;
             }
             /* An event was found and pumped into the SDL events queue. Continue the loop
               to let SDL_PeepEvents pick it up .*/
@@ -880,7 +880,13 @@ SDL_WaitEventTimeout(SDL_Event * event, int timeout)
     }
 
     if (!need_polling && _this && _this->WaitEventTimeout && _this->SendWakeupEvent) {
-        return SDL_WaitEventTimeout_Device(_this, wakeup_window, event, timeout);
+        int status = SDL_WaitEventTimeout_Device(_this, wakeup_window, event, timeout);
+
+        /* There may be implementation-defined conditions where the backend cannot
+           reliably wait for the next event. If that happens, fall back to polling */
+        if (status >= 0) {
+            return status;
+        }
     }
 
     for (;;) {

+ 5 - 1
src/video/windows/SDL_windowsevents.c

@@ -1303,9 +1303,13 @@ WIN_WaitEventTimeout(_THIS, int timeout)
             TranslateMessage(&msg);
             DispatchMessage(&msg);
             return 1;
+        } else {
+            return 0;
         }
+    } else {
+        /* Fail the wait so the caller falls back to polling */
+        return -1;
     }
-    return 0;
 }
 
 void