Handle assertion failures when SDL_Init() isn't called.
authorRyan C. Gordon <icculus@icculus.org>
Wed, 13 Jan 2010 09:44:17 +0000
changeset 36626a0b3048f271
parent 3661 22b6a0c7ea6e
child 3663 bc50cd16bb07
Handle assertion failures when SDL_Init() isn't called.
src/SDL_assert.c
     1.1 --- a/src/SDL_assert.c	Wed Jan 13 09:13:37 2010 +0000
     1.2 +++ b/src/SDL_assert.c	Wed Jan 13 09:44:17 2010 +0000
     1.3 @@ -351,8 +351,19 @@
     1.4                      int line)
     1.5  {
     1.6      static int assertion_running = 0;
     1.7 +    static SDL_SpinLock spinlock = 0;
     1.8      SDL_assert_state state = SDL_ASSERTION_IGNORE;
     1.9  
    1.10 +    SDL_AtomicLock(&spinlock);
    1.11 +    if (assertion_mutex == NULL) { /* never called SDL_Init()? */
    1.12 +        assertion_mutex = SDL_CreateMutex();
    1.13 +        if (assertion_mutex == NULL) {
    1.14 +            SDL_AtomicUnlock(&spinlock);
    1.15 +            return SDL_ASSERTION_IGNORE;   /* oh well, I guess. */
    1.16 +        }
    1.17 +    }
    1.18 +    SDL_AtomicUnlock(&spinlock);
    1.19 +
    1.20      if (SDL_LockMutex(assertion_mutex) < 0) {
    1.21          return SDL_ASSERTION_IGNORE;   /* oh well, I guess. */
    1.22      }