| Summary: | SDL_SetEventFilter()'s event deletion process is not safe against intervening event push. | ||
|---|---|---|---|
| Product: | SDL | Reporter: | Shigekazu Hukui <shigerello> |
| Component: | events | Assignee: | Sam Lantinga <slouken> |
| Status: | RESOLVED FIXED | QA Contact: | Sam Lantinga <slouken> |
| Severity: | normal | ||
| Priority: | P2 | ||
| Version: | HG 2.0 | ||
| Hardware: | All | ||
| OS: | All | ||
Fixed, thanks! http://hg.libsdl.org/SDL/rev/c6b3d3c32507 |
*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.