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 2414 - Execute event watchers in the order they were added
Summary: Execute event watchers in the order they were added
Status: RESOLVED FIXED
Alias: None
Product: SDL
Classification: Unclassified
Component: events (show other bugs)
Version: HG 2.1
Hardware: x86_64 Linux
: P2 normal
Assignee: Sam Lantinga
QA Contact: Sam Lantinga
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2014-02-22 20:35 UTC by Leonardo
Modified: 2014-02-22 23:27 UTC (History)
0 users

See Also:


Attachments
Add the watcher to the tail of event watchers (997 bytes, patch)
2014-02-22 20:35 UTC, Leonardo
Details | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description Leonardo 2014-02-22 20:35:54 UTC
Created attachment 1572 [details]
Add the watcher to the tail of event watchers

Event watchers are being executed on the inverse order they are added because they are added to the head of the SDL_event_watchers list.

Since watchers are allowed to change events before they are reported (they shouldn't, imo), this breaks code that rely on watcher execution order (such as distributed event handling).

An easy scenario to see this behaving weird to the user is if you add an event watcher to check mouse coordinates and check them again in your event loop. If you add the watcher after renderer's one (which always happens after you have initialized renderer), you get the same event but different coordinates.

The proposed patch adds the event watcher in the tail of the list, not in the beginning, and correctly fixes this problem.
Comment 1 Sam Lantinga 2014-02-22 23:27:41 UTC
Fixed, thanks!
https://hg.libsdl.org/SDL/rev/80c193c7c8c8