Only return from SDL_PollEvent() if the last sentinel is consumed

This commit is contained in:
Sam Lantinga 2022-01-06 12:56:07 -08:00
parent c9ff90b949
commit 8ff2166855
1 changed files with 6 additions and 1 deletions

View File

@ -984,6 +984,7 @@ SDL_WaitEventTimeout(SDL_Event * event, int timeout)
} }
/* First check for existing events */ /* First check for existing events */
retry:
switch (SDL_PeepEventsInternal(event, 1, SDL_GETEVENT, SDL_FIRSTEVENT, SDL_LASTEVENT, include_sentinel)) { switch (SDL_PeepEventsInternal(event, 1, SDL_GETEVENT, SDL_FIRSTEVENT, SDL_LASTEVENT, include_sentinel)) {
case -1: case -1:
return 0; return 0;
@ -995,7 +996,11 @@ SDL_WaitEventTimeout(SDL_Event * event, int timeout)
break; break;
default: default:
if (event && event->type == SDL_POLLSENTINEL) { if (event && event->type == SDL_POLLSENTINEL) {
/* Reached the end of a poll cycle, and no timeout */ /* Reached the end of a poll cycle, and not willing to wait */
if (SDL_AtomicGet(&SDL_sentinel_pending) > 0) {
/* We have another sentinel pending, skip this and keep going */
goto retry;
}
return 0; return 0;
} }
/* Has existing events */ /* Has existing events */