Skip to content

Commit 8432026

Browse files
committed
Fixed the queue filling up with sentinel events when the WaitEvent call is passed NULL for the event
The use case is an application that waits for events on the main thread and dispatches them on a separate thread.
1 parent f0e768d commit 8432026

File tree

1 file changed

+5
-1
lines changed

1 file changed

+5
-1
lines changed

src/events/SDL_events.c

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -891,7 +891,11 @@ SDL_WaitEventTimeout_Device(_THIS, SDL_Window *wakeup_window, SDL_Event * event,
891891
c) Periodic processing that takes place in some platform PumpEvents() functions happens
892892
d) Signals received in WaitEventTimeout() are turned into SDL events
893893
*/
894-
SDL_PumpEventsInternal(SDL_TRUE);
894+
/* We only want a single sentinel in the queue. We could get more than one if event is NULL,
895+
* since the SDL_PeepEvents() call below won't remove it in that case.
896+
*/
897+
SDL_bool add_sentinel = (SDL_AtomicGet(&SDL_sentinel_pending) == 0) ? SDL_TRUE : SDL_FALSE;
898+
SDL_PumpEventsInternal(add_sentinel);
895899

896900
if (!_this->wakeup_lock || SDL_LockMutex(_this->wakeup_lock) == 0) {
897901
int status = SDL_PeepEvents(event, 1, SDL_GETEVENT, SDL_FIRSTEVENT, SDL_LASTEVENT);

0 commit comments

Comments
 (0)