Jelajahi Sumber

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.
Sam Lantinga 4 tahun lalu
induk
melakukan
84320266f2
1 mengubah file dengan 5 tambahan dan 1 penghapusan
  1. 5 1
      src/events/SDL_events.c

+ 5 - 1
src/events/SDL_events.c

@@ -891,7 +891,11 @@ SDL_WaitEventTimeout_Device(_THIS, SDL_Window *wakeup_window, SDL_Event * event,
            c) Periodic processing that takes place in some platform PumpEvents() functions happens
            c) Periodic processing that takes place in some platform PumpEvents() functions happens
            d) Signals received in WaitEventTimeout() are turned into SDL events
            d) Signals received in WaitEventTimeout() are turned into SDL events
         */
         */
-        SDL_PumpEventsInternal(SDL_TRUE);
+        /* We only want a single sentinel in the queue. We could get more than one if event is NULL,
+         * since the SDL_PeepEvents() call below won't remove it in that case.
+         */
+        SDL_bool add_sentinel = (SDL_AtomicGet(&SDL_sentinel_pending) == 0) ? SDL_TRUE : SDL_FALSE;
+        SDL_PumpEventsInternal(add_sentinel);
 
 
         if (!_this->wakeup_lock || SDL_LockMutex(_this->wakeup_lock) == 0) {
         if (!_this->wakeup_lock || SDL_LockMutex(_this->wakeup_lock) == 0) {
             int status = SDL_PeepEvents(event, 1, SDL_GETEVENT, SDL_FIRSTEVENT, SDL_LASTEVENT);
             int status = SDL_PeepEvents(event, 1, SDL_GETEVENT, SDL_FIRSTEVENT, SDL_LASTEVENT);