changeset 3662:6a0b3048f271

Handle assertion failures when SDL_Init() isn't called.
author Ryan C. Gordon <icculus@icculus.org>
date Wed, 13 Jan 2010 09:44:17 +0000
parents 22b6a0c7ea6e
children bc50cd16bb07
files src/SDL_assert.c
diffstat 1 files changed, 11 insertions(+), 0 deletions(-) [+]
line wrap: on
line diff
--- a/src/SDL_assert.c	Wed Jan 13 09:13:37 2010 +0000
+++ b/src/SDL_assert.c	Wed Jan 13 09:44:17 2010 +0000
@@ -351,8 +351,19 @@
                     int line)
 {
     static int assertion_running = 0;
+    static SDL_SpinLock spinlock = 0;
     SDL_assert_state state = SDL_ASSERTION_IGNORE;
 
+    SDL_AtomicLock(&spinlock);
+    if (assertion_mutex == NULL) { /* never called SDL_Init()? */
+        assertion_mutex = SDL_CreateMutex();
+        if (assertion_mutex == NULL) {
+            SDL_AtomicUnlock(&spinlock);
+            return SDL_ASSERTION_IGNORE;   /* oh well, I guess. */
+        }
+    }
+    SDL_AtomicUnlock(&spinlock);
+
     if (SDL_LockMutex(assertion_mutex) < 0) {
         return SDL_ASSERTION_IGNORE;   /* oh well, I guess. */
     }