From 4b65e24da80c8740853c1081c629b643952abbe3 Mon Sep 17 00:00:00 2001 From: "Ryan C. Gordon" Date: Wed, 13 Jan 2010 09:44:17 +0000 Subject: [PATCH] Handle assertion failures when SDL_Init() isn't called. --- src/SDL_assert.c | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/src/SDL_assert.c b/src/SDL_assert.c index a9b220306..51301242e 100644 --- a/src/SDL_assert.c +++ b/src/SDL_assert.c @@ -351,8 +351,19 @@ SDL_ReportAssertion(SDL_assert_data *data, const char *func, const char *file, 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. */ }