src/events/SDL_events.c
changeset 8234 80c193c7c8c8
parent 8149 681eb46b8ac4
child 8583 fb2933ca805f
     1.1 --- a/src/events/SDL_events.c	Sat Feb 22 15:23:09 2014 -0800
     1.2 +++ b/src/events/SDL_events.c	Sat Feb 22 15:27:11 2014 -0800
     1.3 @@ -503,17 +503,28 @@
     1.4  void
     1.5  SDL_AddEventWatch(SDL_EventFilter filter, void *userdata)
     1.6  {
     1.7 -    SDL_EventWatcher *watcher;
     1.8 +    SDL_EventWatcher *watcher, *tail;
     1.9  
    1.10      watcher = (SDL_EventWatcher *)SDL_malloc(sizeof(*watcher));
    1.11      if (!watcher) {
    1.12          /* Uh oh... */
    1.13          return;
    1.14      }
    1.15 +
    1.16 +    /* create the watcher */
    1.17      watcher->callback = filter;
    1.18      watcher->userdata = userdata;
    1.19 -    watcher->next = SDL_event_watchers;
    1.20 -    SDL_event_watchers = watcher;
    1.21 +    watcher->next = NULL;
    1.22 +
    1.23 +    /* add the watcher to the end of the list */
    1.24 +    if (SDL_event_watchers) {
    1.25 +        for (tail = SDL_event_watchers; tail->next; tail = tail->next) {
    1.26 +            continue;
    1.27 +        }
    1.28 +        tail->next = watcher;
    1.29 +    } else {
    1.30 +        SDL_event_watchers = watcher;
    1.31 +    }
    1.32  }
    1.33  
    1.34  /* FIXME: This is not thread-safe yet */