src/SDL_assert.c
author Sam Lantinga <slouken@libsdl.org>
Sat, 26 Jun 2010 08:56:48 -0700
changeset 4472 791b3256fb22
parent 3697 f7b03b6838cb
child 5006 8e8876e4aec6
permissions -rw-r--r--
Mostly cleaned up warnings with -Wmissing-prototypes
slouken@3647
     1
/*
slouken@3647
     2
    SDL - Simple DirectMedia Layer
slouken@3697
     3
    Copyright (C) 1997-2010 Sam Lantinga
slouken@3647
     4
slouken@3647
     5
    This library is free software; you can redistribute it and/or
slouken@3647
     6
    modify it under the terms of the GNU Lesser General Public
slouken@3647
     7
    License as published by the Free Software Foundation; either
slouken@3647
     8
    version 2.1 of the License, or (at your option) any later version.
slouken@3647
     9
slouken@3647
    10
    This library is distributed in the hope that it will be useful,
slouken@3647
    11
    but WITHOUT ANY WARRANTY; without even the implied warranty of
slouken@3647
    12
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
slouken@3647
    13
    Lesser General Public License for more details.
slouken@3647
    14
slouken@3647
    15
    You should have received a copy of the GNU Lesser General Public
slouken@3647
    16
    License along with this library; if not, write to the Free Software
slouken@3647
    17
    Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
slouken@3647
    18
slouken@3647
    19
    Sam Lantinga
slouken@3647
    20
    slouken@libsdl.org
slouken@3647
    21
*/
slouken@3647
    22
slouken@3651
    23
#include "SDL.h"
slouken@3647
    24
#include "SDL_assert.h"
slouken@4472
    25
#include "SDL_assert_c.h"
slouken@3671
    26
#include "video/SDL_sysvideo.h"
slouken@3647
    27
slouken@3647
    28
#ifdef _WINDOWS
slouken@3647
    29
#define WIN32_LEAN_AND_MEAN 1
slouken@3647
    30
#include <windows.h>
slouken@3647
    31
#else  /* fprintf, _exit(), etc. */
slouken@3647
    32
#include <stdio.h>
slouken@3647
    33
#include <stdlib.h>
icculus@3648
    34
#include <unistd.h>
slouken@3647
    35
#endif
slouken@3647
    36
icculus@3670
    37
static SDL_assert_state
icculus@3670
    38
SDL_PromptAssertion(const SDL_assert_data *data, void *userdata);
icculus@3670
    39
icculus@3670
    40
/*
icculus@3670
    41
 * We keep all triggered assertions in a singly-linked list so we can
slouken@3647
    42
 *  generate a report later.
slouken@3647
    43
 */
slouken@3647
    44
static SDL_assert_data assertion_list_terminator = { 0, 0, 0, 0, 0, 0, 0 };
slouken@3647
    45
static SDL_assert_data *triggered_assertions = &assertion_list_terminator;
icculus@3670
    46
icculus@3670
    47
static SDL_mutex *assertion_mutex = NULL;
icculus@3670
    48
static SDL_AssertionHandler assertion_handler = SDL_PromptAssertion;
icculus@3670
    49
static void *assertion_userdata = NULL;
slouken@3647
    50
icculus@3648
    51
#ifdef __GNUC__
icculus@3661
    52
static void
icculus@3661
    53
debug_print(const char *fmt, ...) __attribute__((format (printf, 1, 2)));
icculus@3648
    54
#endif
icculus@3648
    55
icculus@3648
    56
static void
icculus@3648
    57
debug_print(const char *fmt, ...)
slouken@3647
    58
{
slouken@3647
    59
#ifdef _WINDOWS
slouken@3647
    60
    /* Format into a buffer for OutputDebugStringA(). */
slouken@3647
    61
    char buf[1024];
slouken@3647
    62
    char *startptr;
slouken@3647
    63
    char *ptr;
slouken@3647
    64
    int len;
slouken@3647
    65
    va_list ap;
slouken@3647
    66
    va_start(ap, fmt);
slouken@3647
    67
    len = (int) SDL_vsnprintf(buf, sizeof (buf), fmt, ap);
slouken@3647
    68
    va_end(ap);
slouken@3647
    69
slouken@3647
    70
    /* Visual C's vsnprintf() may not null-terminate the buffer. */
slouken@3647
    71
    if ((len >= sizeof (buf)) || (len < 0)) {
slouken@3647
    72
        buf[sizeof (buf) - 1] = '\0';
slouken@3647
    73
    }
slouken@3647
    74
slouken@3647
    75
    /* Write it, sorting out the Unix newlines... */
slouken@3647
    76
    startptr = buf;
slouken@3647
    77
    for (ptr = startptr; *ptr; ptr++) {
slouken@3647
    78
        if (*ptr == '\n') {
slouken@3647
    79
            *ptr = '\0';
slouken@3647
    80
            OutputDebugStringA(startptr);
slouken@3647
    81
            OutputDebugStringA("\r\n");
slouken@3647
    82
            startptr = ptr+1;
slouken@3647
    83
        }
slouken@3647
    84
    }
slouken@3647
    85
slouken@3647
    86
    /* catch that last piece if it didn't have a newline... */
slouken@3647
    87
    if (startptr != ptr) {
slouken@3647
    88
        OutputDebugStringA(startptr);
slouken@3647
    89
    }
slouken@3647
    90
#else
slouken@3647
    91
    /* Unix has it easy. Just dump it to stderr. */
slouken@3647
    92
    va_list ap;
slouken@3647
    93
    va_start(ap, fmt);
icculus@3669
    94
    vfprintf(stderr, fmt, ap);
slouken@3647
    95
    va_end(ap);
slouken@3647
    96
    fflush(stderr);
slouken@3647
    97
#endif
slouken@3647
    98
}
slouken@3647
    99
slouken@3647
   100
slouken@3647
   101
#ifdef _WINDOWS
slouken@3647
   102
static SDL_assert_state SDL_Windows_AssertChoice = SDL_ASSERTION_ABORT;
slouken@3647
   103
static const SDL_assert_data *SDL_Windows_AssertData = NULL;
slouken@3647
   104
slouken@3647
   105
static LRESULT CALLBACK
slouken@3647
   106
SDL_Assertion_WndProc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam)
slouken@3647
   107
{
slouken@3647
   108
    switch (msg)
slouken@3647
   109
    {
slouken@3647
   110
        case WM_CREATE:
slouken@3647
   111
        {
slouken@3647
   112
            /* !!! FIXME: all this code stinks. */
slouken@3647
   113
            const SDL_assert_data *data = SDL_Windows_AssertData;
slouken@3647
   114
            char buf[1024];
slouken@3647
   115
            const int w = 100;
slouken@3647
   116
            const int h = 25;
slouken@3647
   117
            const int gap = 10;
slouken@3647
   118
            int x = gap;
slouken@3647
   119
            int y = 50;
slouken@3647
   120
            int len;
slouken@3647
   121
            int i;
slouken@3647
   122
            static const struct { 
slouken@3647
   123
                const char *name;
slouken@3647
   124
                SDL_assert_state state;
slouken@3647
   125
            } buttons[] = {
slouken@3647
   126
                {"Abort", SDL_ASSERTION_ABORT },
slouken@3647
   127
                {"Break", SDL_ASSERTION_BREAK },
slouken@3647
   128
                {"Retry", SDL_ASSERTION_RETRY },
slouken@3647
   129
                {"Ignore", SDL_ASSERTION_IGNORE },
slouken@3647
   130
                {"Always Ignore", SDL_ASSERTION_ALWAYS_IGNORE },
slouken@3647
   131
            };
slouken@3647
   132
slouken@3647
   133
            len = (int) SDL_snprintf(buf, sizeof (buf), 
slouken@3647
   134
                         "Assertion failure at %s (%s:%d), triggered %u time%s:\r\n  '%s'",
slouken@3647
   135
                         data->function, data->filename, data->linenum,
slouken@3647
   136
                         data->trigger_count, (data->trigger_count == 1) ? "" : "s",
slouken@3647
   137
                         data->condition);
slouken@3647
   138
            if ((len < 0) || (len >= sizeof (buf))) {
slouken@3647
   139
                buf[sizeof (buf) - 1] = '\0';
slouken@3647
   140
            }
slouken@3647
   141
slouken@3647
   142
            CreateWindowA("STATIC", buf,
slouken@3647
   143
                         WS_VISIBLE | WS_CHILD | SS_LEFT,
slouken@3647
   144
                         x, y, 550, 100,
slouken@3647
   145
                         hwnd, (HMENU) 1, NULL, NULL);
slouken@3647
   146
            y += 110;
slouken@3647
   147
slouken@3647
   148
            for (i = 0; i < (sizeof (buttons) / sizeof (buttons[0])); i++) {
slouken@3647
   149
                CreateWindowA("BUTTON", buttons[i].name,
slouken@3647
   150
                         WS_VISIBLE | WS_CHILD,
slouken@3647
   151
                         x, y, w, h,
slouken@3647
   152
                         hwnd, (HMENU) buttons[i].state, NULL, NULL);
slouken@3647
   153
                x += w + gap;
slouken@3647
   154
            }
slouken@3647
   155
            break;
slouken@3647
   156
        }
slouken@3647
   157
slouken@3647
   158
        case WM_COMMAND:
slouken@3647
   159
            SDL_Windows_AssertChoice = ((SDL_assert_state) (LOWORD(wParam)));
slouken@3647
   160
            SDL_Windows_AssertData = NULL;
slouken@3647
   161
            break;
slouken@3647
   162
slouken@3647
   163
        case WM_DESTROY:
slouken@3647
   164
            SDL_Windows_AssertData = NULL;
slouken@3647
   165
            break;
slouken@3647
   166
    }
slouken@3647
   167
slouken@3647
   168
    return DefWindowProc(hwnd, msg, wParam, lParam);
slouken@3647
   169
}
slouken@3647
   170
slouken@3647
   171
static SDL_assert_state
slouken@3647
   172
SDL_PromptAssertion_windows(const SDL_assert_data *data)
slouken@3647
   173
{
slouken@3647
   174
    HINSTANCE hInstance = 0;  /* !!! FIXME? */
slouken@3647
   175
    HWND hwnd;
slouken@3647
   176
    MSG msg;
slouken@3647
   177
    WNDCLASS wc = {0};
slouken@3647
   178
slouken@3647
   179
    SDL_Windows_AssertChoice = SDL_ASSERTION_ABORT;
slouken@3647
   180
    SDL_Windows_AssertData = data;
slouken@3647
   181
slouken@3647
   182
    wc.lpszClassName = TEXT("SDL_assert");
slouken@3647
   183
    wc.hInstance = hInstance ;
slouken@3647
   184
    wc.hbrBackground = GetSysColorBrush(COLOR_3DFACE);
slouken@3647
   185
    wc.lpfnWndProc = SDL_Assertion_WndProc;
slouken@3647
   186
    wc.hCursor = LoadCursor(0, IDC_ARROW);
slouken@3647
   187
  
slouken@3647
   188
    RegisterClass(&wc);
slouken@3647
   189
    hwnd = CreateWindow(wc.lpszClassName, TEXT("SDL assertion failure"),
slouken@3647
   190
                 WS_OVERLAPPEDWINDOW | WS_VISIBLE,
slouken@3647
   191
                 150, 150, 570, 260, 0, 0, hInstance, 0);  
slouken@3647
   192
slouken@3647
   193
    while (GetMessage(&msg, NULL, 0, 0) && (SDL_Windows_AssertData != NULL)) {
slouken@3647
   194
        TranslateMessage(&msg);
slouken@3647
   195
        DispatchMessage(&msg);
slouken@3647
   196
    }
slouken@3647
   197
slouken@3647
   198
    DestroyWindow(hwnd);
slouken@3647
   199
    UnregisterClass(wc.lpszClassName, hInstance);
slouken@3647
   200
    return SDL_Windows_AssertChoice;
slouken@3647
   201
}
slouken@3647
   202
#endif
slouken@3647
   203
slouken@3647
   204
slouken@3647
   205
static void SDL_AddAssertionToReport(SDL_assert_data *data)
slouken@3647
   206
{
slouken@3647
   207
    /* (data) is always a static struct defined with the assert macros, so
slouken@3647
   208
       we don't have to worry about copying or allocating them. */
slouken@3647
   209
    if (data->next == NULL) {  /* not yet added? */
slouken@3647
   210
        data->next = triggered_assertions;
slouken@3647
   211
        triggered_assertions = data;
slouken@3647
   212
    }
slouken@3647
   213
}
slouken@3647
   214
icculus@3670
   215
slouken@3647
   216
static void SDL_GenerateAssertionReport(void)
slouken@3647
   217
{
icculus@3670
   218
    const SDL_assert_data *item;
icculus@3670
   219
icculus@3670
   220
    /* only do this if the app hasn't assigned an assertion handler. */
icculus@3670
   221
    if (assertion_handler != SDL_PromptAssertion)
icculus@3670
   222
        return;
icculus@3670
   223
icculus@3670
   224
    item = SDL_GetAssertionReport();
icculus@3670
   225
    if (item->condition)
slouken@3647
   226
    {
slouken@3647
   227
        debug_print("\n\nSDL assertion report.\n");
slouken@3647
   228
        debug_print("All SDL assertions between last init/quit:\n\n");
slouken@3647
   229
icculus@3670
   230
        while (item->condition) {
slouken@3647
   231
            debug_print(
slouken@3647
   232
                "'%s'\n"
slouken@3647
   233
                "    * %s (%s:%d)\n"
slouken@3647
   234
                "    * triggered %u time%s.\n"
slouken@3647
   235
                "    * always ignore: %s.\n",
slouken@3647
   236
                item->condition, item->function, item->filename,
slouken@3647
   237
                item->linenum, item->trigger_count,
slouken@3647
   238
                (item->trigger_count == 1) ? "" : "s",
slouken@3647
   239
                item->always_ignore ? "yes" : "no");
slouken@3647
   240
            item = item->next;
slouken@3647
   241
        }
slouken@3647
   242
        debug_print("\n");
slouken@3647
   243
icculus@3670
   244
        SDL_ResetAssertionReport();
slouken@3647
   245
    }
slouken@3647
   246
}
slouken@3647
   247
icculus@3661
   248
static void SDL_ExitProcess(int exitcode)
slouken@3647
   249
{
slouken@3647
   250
#ifdef _WINDOWS
slouken@3647
   251
    ExitProcess(42);
slouken@3656
   252
#else
slouken@3647
   253
    _exit(42);
slouken@3647
   254
#endif
slouken@3647
   255
}
icculus@3661
   256
icculus@3661
   257
static void SDL_AbortAssertion(void)
icculus@3661
   258
{
icculus@3661
   259
    SDL_Quit();
icculus@3661
   260
    SDL_ExitProcess(42);
icculus@3661
   261
}
icculus@3661
   262
slouken@3647
   263
icculus@3670
   264
static SDL_assert_state
icculus@3670
   265
SDL_PromptAssertion(const SDL_assert_data *data, void *userdata)
slouken@3647
   266
{
slouken@3647
   267
    const char *envr;
slouken@3657
   268
    SDL_assert_state state = SDL_ASSERTION_ABORT;
slouken@3685
   269
    SDL_Window *window;
slouken@3647
   270
icculus@3670
   271
    (void) userdata;  /* unused in default handler. */
icculus@3670
   272
slouken@3647
   273
    debug_print("\n\n"
slouken@3647
   274
                "Assertion failure at %s (%s:%d), triggered %u time%s:\n"
slouken@3647
   275
                "  '%s'\n"
slouken@3647
   276
                "\n",
slouken@3647
   277
                data->function, data->filename, data->linenum,
slouken@3647
   278
                data->trigger_count, (data->trigger_count == 1) ? "" : "s",
slouken@3647
   279
                data->condition);
slouken@3647
   280
slouken@3655
   281
    /* let env. variable override, so unit tests won't block in a GUI. */
slouken@3647
   282
    envr = SDL_getenv("SDL_ASSERT");
slouken@3647
   283
    if (envr != NULL) {
slouken@3647
   284
        if (SDL_strcmp(envr, "abort") == 0) {
slouken@3647
   285
            return SDL_ASSERTION_ABORT;
slouken@3647
   286
        } else if (SDL_strcmp(envr, "break") == 0) {
slouken@3647
   287
            return SDL_ASSERTION_BREAK;
slouken@3647
   288
        } else if (SDL_strcmp(envr, "retry") == 0) {
slouken@3647
   289
            return SDL_ASSERTION_RETRY;
slouken@3647
   290
        } else if (SDL_strcmp(envr, "ignore") == 0) {
slouken@3647
   291
            return SDL_ASSERTION_IGNORE;
slouken@3647
   292
        } else if (SDL_strcmp(envr, "always_ignore") == 0) {
slouken@3647
   293
            return SDL_ASSERTION_ALWAYS_IGNORE;
slouken@3647
   294
        } else {
slouken@3647
   295
            return SDL_ASSERTION_ABORT;  /* oh well. */
slouken@3647
   296
        }
slouken@3647
   297
    }
slouken@3647
   298
slouken@3657
   299
    /* Leave fullscreen mode, if possible (scary!) */
slouken@3657
   300
    window = SDL_GetFocusWindow();
slouken@3657
   301
    if (window) {
slouken@3657
   302
        if (SDL_GetWindowFlags(window) & SDL_WINDOW_FULLSCREEN) {
slouken@3657
   303
            SDL_MinimizeWindow(window);
slouken@3657
   304
        } else {
icculus@3670
   305
            /* !!! FIXME: ungrab the input if we're not fullscreen? */
slouken@3657
   306
            /* No need to mess with the window */
slouken@3657
   307
            window = 0;
slouken@3657
   308
        }
slouken@3657
   309
    }
slouken@3657
   310
slouken@3647
   311
    /* platform-specific UI... */
slouken@3647
   312
slouken@3647
   313
#ifdef _WINDOWS
slouken@3657
   314
    state = SDL_PromptAssertion_windows(data);
slouken@3647
   315
slouken@3690
   316
#elif __MACOSX__
slouken@3647
   317
    /* This has to be done in an Objective-C (*.m) file, so we call out. */
slouken@3647
   318
    extern SDL_assert_state SDL_PromptAssertion_cocoa(const SDL_assert_data *);
slouken@3657
   319
    state = SDL_PromptAssertion_cocoa(data);
slouken@3647
   320
slouken@3657
   321
#else
slouken@3647
   322
    /* this is a little hacky. */
slouken@3647
   323
    for ( ; ; ) {
slouken@3647
   324
        char buf[32];
slouken@3647
   325
        fprintf(stderr, "Abort/Break/Retry/Ignore/AlwaysIgnore? [abriA] : ");
slouken@3647
   326
        fflush(stderr);
slouken@3647
   327
        if (fgets(buf, sizeof (buf), stdin) == NULL) {
slouken@3657
   328
            break;
slouken@3647
   329
        }
slouken@3647
   330
slouken@3647
   331
        if (SDL_strcmp(buf, "a") == 0) {
slouken@3657
   332
            state = SDL_ASSERTION_ABORT;
slouken@3657
   333
            break;
slouken@3647
   334
        } else if (SDL_strcmp(envr, "b") == 0) {
slouken@3657
   335
            state = SDL_ASSERTION_BREAK;
slouken@3657
   336
            break;
slouken@3647
   337
        } else if (SDL_strcmp(envr, "r") == 0) {
slouken@3657
   338
            state = SDL_ASSERTION_RETRY;
slouken@3657
   339
            break;
slouken@3647
   340
        } else if (SDL_strcmp(envr, "i") == 0) {
slouken@3657
   341
            state = SDL_ASSERTION_IGNORE;
slouken@3657
   342
            break;
slouken@3647
   343
        } else if (SDL_strcmp(envr, "A") == 0) {
slouken@3657
   344
            state = SDL_ASSERTION_ALWAYS_IGNORE;
slouken@3657
   345
            break;
slouken@3647
   346
        }
slouken@3647
   347
    }
slouken@3647
   348
#endif
slouken@3647
   349
slouken@3657
   350
    /* Re-enter fullscreen mode */
slouken@3657
   351
    if (window) {
slouken@3657
   352
        SDL_RestoreWindow(window);
slouken@3657
   353
    }
slouken@3657
   354
slouken@3657
   355
    return state;
slouken@3647
   356
}
slouken@3647
   357
slouken@3647
   358
slouken@3647
   359
SDL_assert_state
slouken@3655
   360
SDL_ReportAssertion(SDL_assert_data *data, const char *func, const char *file,
slouken@3655
   361
                    int line)
slouken@3647
   362
{
icculus@3661
   363
    static int assertion_running = 0;
icculus@3662
   364
    static SDL_SpinLock spinlock = 0;
icculus@3661
   365
    SDL_assert_state state = SDL_ASSERTION_IGNORE;
slouken@3647
   366
icculus@3662
   367
    SDL_AtomicLock(&spinlock);
icculus@3662
   368
    if (assertion_mutex == NULL) { /* never called SDL_Init()? */
icculus@3662
   369
        assertion_mutex = SDL_CreateMutex();
icculus@3662
   370
        if (assertion_mutex == NULL) {
icculus@3662
   371
            SDL_AtomicUnlock(&spinlock);
icculus@3662
   372
            return SDL_ASSERTION_IGNORE;   /* oh well, I guess. */
icculus@3662
   373
        }
icculus@3662
   374
    }
icculus@3662
   375
    SDL_AtomicUnlock(&spinlock);
icculus@3662
   376
slouken@3647
   377
    if (SDL_LockMutex(assertion_mutex) < 0) {
slouken@3647
   378
        return SDL_ASSERTION_IGNORE;   /* oh well, I guess. */
slouken@3647
   379
    }
slouken@3647
   380
slouken@3647
   381
    /* doing this because Visual C is upset over assigning in the macro. */
slouken@3647
   382
    if (data->trigger_count == 0) {
slouken@3647
   383
        data->function = func;
slouken@3655
   384
        data->filename = file;
slouken@3655
   385
        data->linenum = line;
slouken@3647
   386
    }
slouken@3647
   387
slouken@3647
   388
    SDL_AddAssertionToReport(data);
slouken@3647
   389
slouken@3647
   390
    data->trigger_count++;
icculus@3661
   391
icculus@3661
   392
    assertion_running++;
icculus@3661
   393
    if (assertion_running > 1) {   /* assert during assert! Abort. */
icculus@3661
   394
        if (assertion_running == 2) {
icculus@3661
   395
            SDL_AbortAssertion();
icculus@3661
   396
        } else if (assertion_running == 3) {  /* Abort asserted! */
icculus@3661
   397
            SDL_ExitProcess(42);
icculus@3661
   398
        } else {
icculus@3661
   399
            while (1) { /* do nothing but spin; what else can you do?! */ }
icculus@3661
   400
        }
slouken@3647
   401
    }
slouken@3647
   402
icculus@3661
   403
    if (!data->always_ignore) {
icculus@3670
   404
        state = assertion_handler(data, assertion_userdata);
icculus@3661
   405
    }
slouken@3647
   406
slouken@3647
   407
    switch (state)
slouken@3647
   408
    {
slouken@3647
   409
        case SDL_ASSERTION_ABORT:
slouken@3647
   410
            SDL_AbortAssertion();
slouken@3647
   411
            return SDL_ASSERTION_IGNORE;  /* shouldn't return, but oh well. */
slouken@3647
   412
slouken@3647
   413
        case SDL_ASSERTION_ALWAYS_IGNORE:
slouken@3647
   414
            state = SDL_ASSERTION_IGNORE;
slouken@3647
   415
            data->always_ignore = 1;
slouken@3647
   416
            break;
slouken@3647
   417
slouken@3647
   418
        case SDL_ASSERTION_IGNORE:
slouken@3647
   419
        case SDL_ASSERTION_RETRY:
slouken@3647
   420
        case SDL_ASSERTION_BREAK:
slouken@3647
   421
            break;  /* macro handles these. */
slouken@3647
   422
    }
slouken@3647
   423
icculus@3661
   424
    assertion_running--;
slouken@3647
   425
    SDL_UnlockMutex(assertion_mutex);
slouken@3647
   426
slouken@3647
   427
    return state;
slouken@3647
   428
}
slouken@3647
   429
slouken@3647
   430
slouken@3647
   431
int SDL_AssertionsInit(void)
slouken@3647
   432
{
icculus@3664
   433
    /* this is a no-op at the moment. */
slouken@3647
   434
    return 0;
slouken@3647
   435
}
slouken@3647
   436
slouken@3647
   437
void SDL_AssertionsQuit(void)
slouken@3647
   438
{
slouken@3647
   439
    SDL_GenerateAssertionReport();
icculus@3664
   440
    if (assertion_mutex != NULL) {
icculus@3664
   441
        SDL_DestroyMutex(assertion_mutex);
icculus@3664
   442
        assertion_mutex = NULL;
icculus@3664
   443
    }
icculus@3670
   444
}
icculus@3670
   445
icculus@3670
   446
void SDL_SetAssertionHandler(SDL_AssertionHandler handler, void *userdata)
icculus@3670
   447
{
icculus@3670
   448
    if (handler != NULL) {
icculus@3670
   449
        assertion_handler = handler;
icculus@3670
   450
        assertion_userdata = userdata;
icculus@3670
   451
    } else {
icculus@3670
   452
        assertion_handler = SDL_PromptAssertion;
icculus@3670
   453
        assertion_userdata = NULL;
icculus@3670
   454
    }
icculus@3670
   455
}
icculus@3670
   456
icculus@3670
   457
const SDL_assert_data *SDL_GetAssertionReport(void)
icculus@3670
   458
{
icculus@3670
   459
    return triggered_assertions;
icculus@3670
   460
}
icculus@3670
   461
icculus@3670
   462
void SDL_ResetAssertionReport(void)
icculus@3670
   463
{
icculus@3670
   464
    SDL_assert_data *item = triggered_assertions;
icculus@3670
   465
    SDL_assert_data *next = NULL;
icculus@3670
   466
    for (item = triggered_assertions; item->condition; item = next) {
icculus@3670
   467
        next = (SDL_assert_data *) item->next;
icculus@3670
   468
        item->always_ignore = SDL_FALSE;
icculus@3670
   469
        item->trigger_count = 0;
icculus@3670
   470
        item->next = NULL;
icculus@3670
   471
    }
icculus@3670
   472
icculus@3670
   473
    triggered_assertions = &assertion_list_terminator;
slouken@3647
   474
}
slouken@3647
   475
slouken@3647
   476
/* vi: set ts=4 sw=4 expandtab: */