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

Summary: Execute event watchers in the order they were added
Product: SDL Reporter: Leonardo <leonardo.guilherme>
Component: eventsAssignee: Sam Lantinga <slouken>
Status: RESOLVED FIXED QA Contact: Sam Lantinga <slouken>
Severity: normal    
Priority: P2    
Version: HG 2.1   
Hardware: x86_64   
OS: Linux   
Attachments: Add the watcher to the tail of event watchers

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