Fixed bug #666
authorSam Lantinga <slouken@libsdl.org>
Wed, 16 Dec 2009 00:55:33 +0000
changeset 357341cd18e05965
parent 3572 6bb9952d5029
child 3574 1069834f3ca8
Fixed bug #666

Don't let the event queue overflow with resize events
src/events/SDL_windowevents.c
     1.1 --- a/src/events/SDL_windowevents.c	Wed Dec 16 00:44:53 2009 +0000
     1.2 +++ b/src/events/SDL_windowevents.c	Wed Dec 16 00:55:33 2009 +0000
     1.3 @@ -28,6 +28,21 @@
     1.4  #include "SDL_mouse_c.h"
     1.5  #include "../video/SDL_sysvideo.h"
     1.6  
     1.7 +
     1.8 +static int
     1.9 +RemovePendingSizeEvents(void * userdata, SDL_Event *event)
    1.10 +{
    1.11 +    SDL_Event *new_event = (SDL_Event *)userdata;
    1.12 +
    1.13 +    if (event->type == SDL_WINDOWEVENT &&
    1.14 +        event->window.event == SDL_WINDOWEVENT_RESIZED &&
    1.15 +        event->window.windowID == new_event->window.windowID) {
    1.16 +        /* We're about to post a new size event, drop the old one */
    1.17 +        return 0;
    1.18 +    }
    1.19 +    return 1;
    1.20 +}
    1.21 +
    1.22  int
    1.23  SDL_SendWindowEvent(SDL_WindowID windowID, Uint8 windowevent, int data1,
    1.24                      int data2)
    1.25 @@ -138,6 +153,12 @@
    1.26          event.window.data1 = data1;
    1.27          event.window.data2 = data2;
    1.28          event.window.windowID = windowID;
    1.29 +
    1.30 +        /* Fixes queue overflow with resize events that aren't processed */
    1.31 +        if (windowevent == SDL_WINDOWEVENT_RESIZED) {
    1.32 +            SDL_FilterEvents(RemovePendingSizeEvents, &event);
    1.33 +        }
    1.34 +
    1.35          posted = (SDL_PushEvent(&event) > 0);
    1.36      }
    1.37      return (posted);