Commit 13dd2ccda82909adcc7a1d91644a241b75e5077a

Sam Lantinga 2016-10-01T13:38:30

Fixed bug 3161 - SDL_WINDOWEVENT_EXPOSED event possible queue overflow Marcel Bakker Observed when resizing or moving a window in Windows 7. Depending on how you resize/move your window , you may receive none or a lot of SDL_WINDOWEVENT_EXPOSED events , at the moment you release the mouse button. Maybe add this event to an already existing list of overflow candidates ?

diff --git a/src/events/SDL_windowevents.c b/src/events/SDL_windowevents.c
index 785ea4e..b45015b 100644
--- a/src/events/SDL_windowevents.c
+++ b/src/events/SDL_windowevents.c
@@ -70,6 +70,20 @@ RemovePendingMoveEvents(void * userdata, SDL_Event *event)
     return 1;
 }
 
+static int
+RemovePendingExposedEvents(void * userdata, SDL_Event *event)
+{
+    SDL_Event *new_event = (SDL_Event *)userdata;
+
+    if (event->type == SDL_WINDOWEVENT &&
+        event->window.event == SDL_WINDOWEVENT_EXPOSED &&
+        event->window.windowID == new_event->window.windowID) {
+        /* We're about to post a new exposed event, drop the old one */
+        return 0;
+    }
+    return 1;
+}
+
 int
 SDL_SendWindowEvent(SDL_Window * window, Uint8 windowevent, int data1,
                     int data2)
@@ -195,7 +209,9 @@ SDL_SendWindowEvent(SDL_Window * window, Uint8 windowevent, int data1,
         if (windowevent == SDL_WINDOWEVENT_MOVED) {
             SDL_FilterEvents(RemovePendingMoveEvents, &event);
         }
-
+        if (windowevent == SDL_WINDOWEVENT_EXPOSED) {
+            SDL_FilterEvents(RemovePendingExposedEvents, &event);
+        }
         posted = (SDL_PushEvent(&event) > 0);
     }