From 85b51e6c92d4d2c485f995654eb13bba1a0cc1a4 Mon Sep 17 00:00:00 2001 From: Cameron Gutman Date: Sat, 5 Jun 2021 11:46:47 -0500 Subject: [PATCH] Fall back to polling normally if not operating the win32 message loop In this condition, we cannot safely wait/wake on events. --- src/events/SDL_events.c | 10 ++++++++-- src/video/windows/SDL_windowsevents.c | 6 +++++- 2 files changed, 13 insertions(+), 3 deletions(-) diff --git a/src/events/SDL_events.c b/src/events/SDL_events.c index 4f8f91ccc..69990cf1d 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 a8108a8ea..2d47759f0 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