src/events/SDL_events.c
changeset 8234 80c193c7c8c8
parent 8149 681eb46b8ac4
child 8583 fb2933ca805f
--- a/src/events/SDL_events.c	Sat Feb 22 15:23:09 2014 -0800
+++ b/src/events/SDL_events.c	Sat Feb 22 15:27:11 2014 -0800
@@ -503,17 +503,28 @@
 void
 SDL_AddEventWatch(SDL_EventFilter filter, void *userdata)
 {
-    SDL_EventWatcher *watcher;
+    SDL_EventWatcher *watcher, *tail;
 
     watcher = (SDL_EventWatcher *)SDL_malloc(sizeof(*watcher));
     if (!watcher) {
         /* Uh oh... */
         return;
     }
+
+    /* create the watcher */
     watcher->callback = filter;
     watcher->userdata = userdata;
-    watcher->next = SDL_event_watchers;
-    SDL_event_watchers = watcher;
+    watcher->next = NULL;
+
+    /* add the watcher to the end of the list */
+    if (SDL_event_watchers) {
+        for (tail = SDL_event_watchers; tail->next; tail = tail->next) {
+            continue;
+        }
+        tail->next = watcher;
+    } else {
+        SDL_event_watchers = watcher;
+    }
 }
 
 /* FIXME: This is not thread-safe yet */