We are currently migrating Bugzilla to GitHub issues.
Any changes made to the bug tracker now will be lost, so please do not post new bugs or make changes to them.
When we're done, all bug URLs will redirect to their equivalent location on the new bug tracker.

Bug 1113 - SDL_SetEventFilter()'s event deletion process is not safe against intervening event push.
Summary: SDL_SetEventFilter()'s event deletion process is not safe against intervening...
Status: RESOLVED FIXED
Alias: None
Product: SDL
Classification: Unclassified
Component: events (show other bugs)
Version: HG 2.0
Hardware: All All
: P2 normal
Assignee: Sam Lantinga
QA Contact: Sam Lantinga
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2011-02-02 17:53 UTC by Shigekazu Hukui
Modified: 2013-05-21 02:05 UTC (History)
0 users

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Shigekazu Hukui 2011-02-02 17:53:25 UTC
*NOTE: I chose SDL version 1.2.14, but I confirmed revision 5136 of SDL 1.3.0 also has this problem.

SDL_SetEventFilter() repeatedly calls SDL_PollEvent() to discard pending events (I assume this was a painful decision to delete pending events, as to the structure of the event queue does not allow easy implementation of non-head-or-tail event deletion, even though it's not impossible).
But whole operation of this event deletion does not lock the event queue (e.g. each interval of SDL_PollEvent(), no mutex), so that it can allow, for example, SDL timer's event push.

The suggestion is to 1) mutex the event queue during the whole operation of event deletion, or 2) do not delete pending events to "overlook" them.
If SDL really cares about enforcing an event filter and allows event loss, choose 1). Otherwise 2) wont hurt I think.


* SDL_event.c of revision 5136 of SDL 1.3.0
void
SDL_SetEventFilter(SDL_EventFilter filter, void *userdata)
{
    SDL_Event bitbucket;

    /* Set filter and discard pending events */
    SDL_EventOK = filter;
    SDL_EventOKParam = userdata;
    while (SDL_PollEvent(&bitbucket) > 0);
}


Setting up mutex before the while() loop above and free it after the loop, if recursive mutex is possible... hmm.
Comment 1 Sam Lantinga 2013-05-21 02:05:05 UTC
Fixed, thanks!
http://hg.libsdl.org/SDL/rev/c6b3d3c32507