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 6588 f739b8044c26
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
--- a/src/events/SDL_events.c	Sun Oct 14 01:05:04 2012 -0700
+++ b/src/events/SDL_events.c	Sun Oct 14 01:30:42 2012 -0700
@@ -63,7 +63,7 @@
     SDL_Event event[MAXEVENTS];
     int wmmsg_next;
     struct SDL_SysWMmsg wmmsg[MAXEVENTS];
-} SDL_EventQ;
+} SDL_EventQ = { NULL, 1 };
 
 
 static __inline__ SDL_bool
@@ -117,18 +117,21 @@
 int
 SDL_StartEventLoop(void)
 {
-    /* Clean out the event queue */
-    SDL_EventQ.lock = NULL;
-    SDL_StopEventLoop();
+    /* We'll leave the event queue alone, since we might have gotten
+       some important events at launch (like SDL_DROPFILE)
+
+       FIXME: Does this introduce any other bugs with events at startup?
+     */
 
     /* No filter to start with, process most event types */
     SDL_EventOK = NULL;
-    SDL_EventState(SDL_DROPFILE, SDL_DISABLE);
     SDL_EventState(SDL_SYSWMEVENT, SDL_DISABLE);
 
     /* Create the lock and set ourselves active */
 #if !SDL_THREADS_DISABLED
-    SDL_EventQ.lock = SDL_CreateMutex();
+    if (!SDL_EventQ.lock) {
+        SDL_EventQ.lock = SDL_CreateMutex();
+    }
     if (SDL_EventQ.lock == NULL) {
         return (-1);
     }
@@ -207,7 +210,7 @@
     }
     /* Lock the event queue */
     used = 0;
-    if (SDL_mutexP(SDL_EventQ.lock) == 0) {
+    if (!SDL_EventQ.lock || SDL_mutexP(SDL_EventQ.lock) == 0) {
         if (action == SDL_ADDEVENT) {
             for (i = 0; i < numevents; ++i) {
                 used += SDL_AddEvent(&events[i]);
@@ -374,7 +377,6 @@
     }
 
     SDL_GestureProcessEvent(event);
-    
 
     return 1;
 }