Allow events at startup so we don't lose important events like SDL_DROPFILE
authorSam Lantinga <slouken@libsdl.org>
Sun, 14 Oct 2012 01:30:42 -0700
changeset 6588f739b8044c26
parent 6587 4ef7c70295c9
child 6589 46d985073364
Allow events at startup so we don't lose important events like SDL_DROPFILE
src/events/SDL_events.c
     1.1 --- a/src/events/SDL_events.c	Sun Oct 14 01:05:04 2012 -0700
     1.2 +++ b/src/events/SDL_events.c	Sun Oct 14 01:30:42 2012 -0700
     1.3 @@ -63,7 +63,7 @@
     1.4      SDL_Event event[MAXEVENTS];
     1.5      int wmmsg_next;
     1.6      struct SDL_SysWMmsg wmmsg[MAXEVENTS];
     1.7 -} SDL_EventQ;
     1.8 +} SDL_EventQ = { NULL, 1 };
     1.9  
    1.10  
    1.11  static __inline__ SDL_bool
    1.12 @@ -117,18 +117,21 @@
    1.13  int
    1.14  SDL_StartEventLoop(void)
    1.15  {
    1.16 -    /* Clean out the event queue */
    1.17 -    SDL_EventQ.lock = NULL;
    1.18 -    SDL_StopEventLoop();
    1.19 +    /* We'll leave the event queue alone, since we might have gotten
    1.20 +       some important events at launch (like SDL_DROPFILE)
    1.21 +
    1.22 +       FIXME: Does this introduce any other bugs with events at startup?
    1.23 +     */
    1.24  
    1.25      /* No filter to start with, process most event types */
    1.26      SDL_EventOK = NULL;
    1.27 -    SDL_EventState(SDL_DROPFILE, SDL_DISABLE);
    1.28      SDL_EventState(SDL_SYSWMEVENT, SDL_DISABLE);
    1.29  
    1.30      /* Create the lock and set ourselves active */
    1.31  #if !SDL_THREADS_DISABLED
    1.32 -    SDL_EventQ.lock = SDL_CreateMutex();
    1.33 +    if (!SDL_EventQ.lock) {
    1.34 +        SDL_EventQ.lock = SDL_CreateMutex();
    1.35 +    }
    1.36      if (SDL_EventQ.lock == NULL) {
    1.37          return (-1);
    1.38      }
    1.39 @@ -207,7 +210,7 @@
    1.40      }
    1.41      /* Lock the event queue */
    1.42      used = 0;
    1.43 -    if (SDL_mutexP(SDL_EventQ.lock) == 0) {
    1.44 +    if (!SDL_EventQ.lock || SDL_mutexP(SDL_EventQ.lock) == 0) {
    1.45          if (action == SDL_ADDEVENT) {
    1.46              for (i = 0; i < numevents; ++i) {
    1.47                  used += SDL_AddEvent(&events[i]);
    1.48 @@ -374,7 +377,6 @@
    1.49      }
    1.50  
    1.51      SDL_GestureProcessEvent(event);
    1.52 -    
    1.53  
    1.54      return 1;
    1.55  }