From 69f2bd151ece3c00d1850d90da137053b1936b16 Mon Sep 17 00:00:00 2001 From: Hans-Kristian Arntzen Date: Sat, 10 Feb 2024 14:01:34 +0100 Subject: [PATCH] Fix broken use of MsgWaitForMultipleObjects. - Timeout < 0 was not handled properly - Return value for success is WAIT_OBJECT_0 + nCount, not positive value --- src/video/windows/SDL_windowsevents.c | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/src/video/windows/SDL_windowsevents.c b/src/video/windows/SDL_windowsevents.c index 33e8a30e62..7ad60e7482 100644 --- a/src/video/windows/SDL_windowsevents.c +++ b/src/video/windows/SDL_windowsevents.c @@ -1687,7 +1687,10 @@ void SDL_SetWindowsMessageHook(SDL_WindowsMessageHook callback, void *userdata) int WIN_WaitEventTimeout(SDL_VideoDevice *_this, Sint64 timeoutNS) { if (g_WindowsEnableMessageLoop) { - if (MsgWaitForMultipleObjects(0, NULL, FALSE, (DWORD)SDL_NS_TO_MS(timeoutNS), QS_ALLINPUT)) { + DWORD timeout, ret; + timeout = timeoutNS < 0 ? INFINITE : (DWORD)SDL_NS_TO_MS(timeoutNS); + ret = MsgWaitForMultipleObjects(0, NULL, FALSE, timeout, QS_ALLINPUT); + if (ret == WAIT_OBJECT_0) { return 1; } else { return 0;