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