Commit 85b51e6c92d4d2c485f995654eb13bba1a0cc1a4

Cameron Gutman 2021-06-05T11:46:47

Fall back to polling normally if not operating the win32 message loop In this condition, we cannot safely wait/wake on events.

diff --git a/src/events/SDL_events.c b/src/events/SDL_events.c
index 4f8f91c..69990cf 100644
--- a/src/events/SDL_events.c
+++ b/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 (;;) {
diff --git a/src/video/windows/SDL_windowsevents.c b/src/video/windows/SDL_windowsevents.c
index a8108a8..2d47759 100644
--- a/src/video/windows/SDL_windowsevents.c
+++ b/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