src/SDL_assert.c
changeset 3661 22b6a0c7ea6e
parent 3657 eaea59cee6f2
child 3662 6a0b3048f271
     1.1 --- a/src/SDL_assert.c	Wed Jan 13 09:10:17 2010 +0000
     1.2 +++ b/src/SDL_assert.c	Wed Jan 13 09:13:37 2010 +0000
     1.3 @@ -42,12 +42,10 @@
     1.4  static SDL_assert_data *triggered_assertions = &assertion_list_terminator;
     1.5  #endif
     1.6  
     1.7 -static void 
     1.8 -debug_print(const char *fmt, ...)
     1.9  #ifdef __GNUC__
    1.10 -__attribute__((format (printf, 1, 2)))
    1.11 +static void
    1.12 +debug_print(const char *fmt, ...) __attribute__((format (printf, 1, 2)));
    1.13  #endif
    1.14 -;
    1.15  
    1.16  static void
    1.17  debug_print(const char *fmt, ...)
    1.18 @@ -239,17 +237,21 @@
    1.19  #endif
    1.20  }
    1.21  
    1.22 -
    1.23 -static void SDL_AbortAssertion(void)
    1.24 +static void SDL_ExitProcess(int exitcode)
    1.25  {
    1.26 -    SDL_Quit();
    1.27  #ifdef _WINDOWS
    1.28      ExitProcess(42);
    1.29  #else
    1.30      _exit(42);
    1.31  #endif
    1.32  }
    1.33 -    
    1.34 +
    1.35 +static void SDL_AbortAssertion(void)
    1.36 +{
    1.37 +    SDL_Quit();
    1.38 +    SDL_ExitProcess(42);
    1.39 +}
    1.40 +
    1.41  
    1.42  static SDL_assert_state SDL_PromptAssertion(const SDL_assert_data *data)
    1.43  {
    1.44 @@ -348,7 +350,8 @@
    1.45  SDL_ReportAssertion(SDL_assert_data *data, const char *func, const char *file,
    1.46                      int line)
    1.47  {
    1.48 -    SDL_assert_state state;
    1.49 +    static int assertion_running = 0;
    1.50 +    SDL_assert_state state = SDL_ASSERTION_IGNORE;
    1.51  
    1.52      if (SDL_LockMutex(assertion_mutex) < 0) {
    1.53          return SDL_ASSERTION_IGNORE;   /* oh well, I guess. */
    1.54 @@ -364,17 +367,25 @@
    1.55      SDL_AddAssertionToReport(data);
    1.56  
    1.57      data->trigger_count++;
    1.58 -    if (data->always_ignore) {
    1.59 -        SDL_UnlockMutex(assertion_mutex);
    1.60 -        return SDL_ASSERTION_IGNORE;
    1.61 +
    1.62 +    assertion_running++;
    1.63 +    if (assertion_running > 1) {   /* assert during assert! Abort. */
    1.64 +        if (assertion_running == 2) {
    1.65 +            SDL_AbortAssertion();
    1.66 +        } else if (assertion_running == 3) {  /* Abort asserted! */
    1.67 +            SDL_ExitProcess(42);
    1.68 +        } else {
    1.69 +            while (1) { /* do nothing but spin; what else can you do?! */ }
    1.70 +        }
    1.71      }
    1.72  
    1.73 -    state = SDL_PromptAssertion(data);
    1.74 +    if (!data->always_ignore) {
    1.75 +        state = SDL_PromptAssertion(data);
    1.76 +    }
    1.77  
    1.78      switch (state)
    1.79      {
    1.80          case SDL_ASSERTION_ABORT:
    1.81 -            SDL_UnlockMutex(assertion_mutex);  /* in case we assert in quit. */
    1.82              SDL_AbortAssertion();
    1.83              return SDL_ASSERTION_IGNORE;  /* shouldn't return, but oh well. */
    1.84  
    1.85 @@ -389,6 +400,7 @@
    1.86              break;  /* macro handles these. */
    1.87      }
    1.88  
    1.89 +    assertion_running--;
    1.90      SDL_UnlockMutex(assertion_mutex);
    1.91  
    1.92      return state;