Fixed bug 1113 - SDL_SetEventFilter()'s event deletion process is not safe against intervening event push.
authorSam Lantinga
Mon, 20 May 2013 23:04:25 -0700
changeset 7201c6b3d3c32507
parent 7200 54c9f310f7c0
child 7202 373d9e4e8ad9
Fixed bug 1113 - SDL_SetEventFilter()'s event deletion process is not safe against intervening event push.

This is not completely thread-safe since it's possible for an event to come in and be unfiltered between the flush call and the setting of the new filter, but it's much better than it was.
src/events/SDL_events.c
     1.1 --- a/src/events/SDL_events.c	Mon May 20 22:05:49 2013 -0700
     1.2 +++ b/src/events/SDL_events.c	Mon May 20 23:04:25 2013 -0700
     1.3 @@ -388,12 +388,11 @@
     1.4  void
     1.5  SDL_SetEventFilter(SDL_EventFilter filter, void *userdata)
     1.6  {
     1.7 -    SDL_Event bitbucket;
     1.8 -
     1.9      /* Set filter and discard pending events */
    1.10 -    SDL_EventOK = filter;
    1.11 +    SDL_EventOK = NULL;
    1.12 +    SDL_FlushEvents(SDL_FIRSTEVENT, SDL_LASTEVENT);
    1.13      SDL_EventOKParam = userdata;
    1.14 -    while (SDL_PollEvent(&bitbucket) > 0);
    1.15 +    SDL_EventOK = filter;
    1.16  }
    1.17  
    1.18  SDL_bool