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 2621 - SDL_ShowMessageBox and SDL_FlushEvents
Summary: SDL_ShowMessageBox and SDL_FlushEvents
Status: RESOLVED INVALID
Alias: None
Product: SDL
Classification: Unclassified
Component: events (show other bugs)
Version: 2.0.2
Hardware: x86_64 Linux
: P2 normal
Assignee: Sam Lantinga
QA Contact: Sam Lantinga
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2014-07-02 09:50 UTC by Daisuke
Modified: 2014-07-09 08:34 UTC (History)
0 users

See Also:


Attachments
FlushEvent testcode (3.00 KB, text/x-csrc)
2014-07-02 09:50 UTC, Daisuke
Details

Note You need to log in before you can comment on or make changes to this bug.
Description Daisuke 2014-07-02 09:50:05 UTC
Created attachment 1724 [details]
FlushEvent testcode

Bug:
Events are not flushed when SDL_FlushEvents is called right after the return of  SDL_ShowMessageBox.

I require events to be ignored that are generated while a messagebox is shown.

Attached file reproduces the problem:
1) start program, clicking inside screen produces printf
2) try closing the program
3) msgbox shows
4) click a few times inside the main window, no printf
5) click "no", msgbox dissapears
6) Queued printfs are shown, proving SDL_FlushEvents to be ignored when called right after return of SDL_ShowMessageBox

I have also added a workaround (same file, enable this with the ifdef top of file) which requires me to call SDL_FlushEvents after calling SDL_PollEvents atleast once. But this is ugly.

Let me know if this is a bug or expected behaviour.
Comment 1 Sam Lantinga 2014-07-09 08:29:51 UTC
SDL_FlushEvents() intentionally doesn't poll for more events so it can safely be called from event handler callback functions.

A better fix for your use case would be just two lines:
SDL_PumpEvents();
SDL_FlushEvents(SDL_FIRSTEVENT, SDL_LASTEVENT);
Comment 2 Sam Lantinga 2014-07-09 08:34:00 UTC
I clarified the documentation to reflect this:
This function only affects currently queued events. If you want to make sure that all pending OS events are flushed, you can call SDL_PumpEvents() on the main thread immediately before the flush call.