src/SDL_assert.c
author Sam Lantinga <slouken@libsdl.org>
Sat, 14 Jan 2012 13:21:19 -0500
changeset 6217 6952b11b7f46
parent 6138 4c64952a58fb
child 6305 601b0e251822
permissions -rwxr-xr-x
Make sure that we use consistent configuration options on platforms like Windows so that command line builds and IDE builds have ABI compatibility.
Make sure we don't clobber SDL_revision.h when building from Mercurial
slouken@3647
     1
/*
slouken@5535
     2
  Simple DirectMedia Layer
slouken@6138
     3
  Copyright (C) 1997-2012 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@6217
    21
#include "SDL_config.h"
slouken@3647
    22
slouken@3651
    23
#include "SDL.h"
slouken@5006
    24
#include "SDL_atomic.h"
slouken@3647
    25
#include "SDL_assert.h"
slouken@4472
    26
#include "SDL_assert_c.h"
slouken@3671
    27
#include "video/SDL_sysvideo.h"
slouken@3647
    28
slouken@5086
    29
#ifdef __WIN32__
slouken@5090
    30
#include "core/windows/SDL_windows.h"
slouken@5086
    31
slouken@5086
    32
#ifndef WS_OVERLAPPEDWINDOW
slouken@5086
    33
#define WS_OVERLAPPEDWINDOW 0
slouken@5086
    34
#endif
slouken@3647
    35
#else  /* fprintf, _exit(), etc. */
slouken@3647
    36
#include <stdio.h>
slouken@3647
    37
#include <stdlib.h>
icculus@3648
    38
#include <unistd.h>
slouken@3647
    39
#endif
slouken@3647
    40
icculus@3670
    41
static SDL_assert_state
icculus@3670
    42
SDL_PromptAssertion(const SDL_assert_data *data, void *userdata);
icculus@3670
    43
icculus@3670
    44
/*
icculus@3670
    45
 * We keep all triggered assertions in a singly-linked list so we can
slouken@3647
    46
 *  generate a report later.
slouken@3647
    47
 */
icculus@5541
    48
static SDL_assert_data *triggered_assertions = NULL;
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. */
icculus@5541
   220
    data->trigger_count++;
icculus@5541
   221
    if (data->trigger_count == 1) {  /* not yet added? */
slouken@3647
   222
        data->next = triggered_assertions;
slouken@3647
   223
        triggered_assertions = data;
slouken@3647
   224
    }
slouken@3647
   225
}
slouken@3647
   226
icculus@3670
   227
slouken@3647
   228
static void SDL_GenerateAssertionReport(void)
slouken@3647
   229
{
icculus@5541
   230
    const SDL_assert_data *item = triggered_assertions;
icculus@3670
   231
icculus@3670
   232
    /* only do this if the app hasn't assigned an assertion handler. */
icculus@5541
   233
    if ((item != NULL) && (assertion_handler != SDL_PromptAssertion)) {
slouken@3647
   234
        debug_print("\n\nSDL assertion report.\n");
slouken@3647
   235
        debug_print("All SDL assertions between last init/quit:\n\n");
slouken@3647
   236
icculus@5541
   237
        while (item != NULL) {
slouken@3647
   238
            debug_print(
slouken@3647
   239
                "'%s'\n"
slouken@3647
   240
                "    * %s (%s:%d)\n"
slouken@3647
   241
                "    * triggered %u time%s.\n"
slouken@3647
   242
                "    * always ignore: %s.\n",
slouken@3647
   243
                item->condition, item->function, item->filename,
slouken@3647
   244
                item->linenum, item->trigger_count,
slouken@3647
   245
                (item->trigger_count == 1) ? "" : "s",
slouken@3647
   246
                item->always_ignore ? "yes" : "no");
slouken@3647
   247
            item = item->next;
slouken@3647
   248
        }
slouken@3647
   249
        debug_print("\n");
slouken@3647
   250
icculus@3670
   251
        SDL_ResetAssertionReport();
slouken@3647
   252
    }
slouken@3647
   253
}
slouken@3647
   254
icculus@3661
   255
static void SDL_ExitProcess(int exitcode)
slouken@3647
   256
{
slouken@5086
   257
#ifdef __WIN32__
slouken@3647
   258
    ExitProcess(42);
slouken@3656
   259
#else
slouken@3647
   260
    _exit(42);
slouken@3647
   261
#endif
slouken@3647
   262
}
icculus@3661
   263
icculus@3661
   264
static void SDL_AbortAssertion(void)
icculus@3661
   265
{
icculus@3661
   266
    SDL_Quit();
icculus@3661
   267
    SDL_ExitProcess(42);
icculus@3661
   268
}
icculus@3661
   269
slouken@3647
   270
icculus@3670
   271
static SDL_assert_state
icculus@3670
   272
SDL_PromptAssertion(const SDL_assert_data *data, void *userdata)
slouken@3647
   273
{
slouken@3647
   274
    const char *envr;
slouken@3657
   275
    SDL_assert_state state = SDL_ASSERTION_ABORT;
slouken@3685
   276
    SDL_Window *window;
slouken@3647
   277
icculus@3670
   278
    (void) userdata;  /* unused in default handler. */
icculus@3670
   279
slouken@3647
   280
    debug_print("\n\n"
slouken@3647
   281
                "Assertion failure at %s (%s:%d), triggered %u time%s:\n"
slouken@3647
   282
                "  '%s'\n"
slouken@3647
   283
                "\n",
slouken@3647
   284
                data->function, data->filename, data->linenum,
slouken@3647
   285
                data->trigger_count, (data->trigger_count == 1) ? "" : "s",
slouken@3647
   286
                data->condition);
slouken@3647
   287
slouken@3655
   288
    /* let env. variable override, so unit tests won't block in a GUI. */
slouken@3647
   289
    envr = SDL_getenv("SDL_ASSERT");
slouken@3647
   290
    if (envr != NULL) {
slouken@3647
   291
        if (SDL_strcmp(envr, "abort") == 0) {
slouken@3647
   292
            return SDL_ASSERTION_ABORT;
slouken@3647
   293
        } else if (SDL_strcmp(envr, "break") == 0) {
slouken@3647
   294
            return SDL_ASSERTION_BREAK;
slouken@3647
   295
        } else if (SDL_strcmp(envr, "retry") == 0) {
slouken@3647
   296
            return SDL_ASSERTION_RETRY;
slouken@3647
   297
        } else if (SDL_strcmp(envr, "ignore") == 0) {
slouken@3647
   298
            return SDL_ASSERTION_IGNORE;
slouken@3647
   299
        } else if (SDL_strcmp(envr, "always_ignore") == 0) {
slouken@3647
   300
            return SDL_ASSERTION_ALWAYS_IGNORE;
slouken@3647
   301
        } else {
slouken@3647
   302
            return SDL_ASSERTION_ABORT;  /* oh well. */
slouken@3647
   303
        }
slouken@3647
   304
    }
slouken@3647
   305
slouken@3657
   306
    /* Leave fullscreen mode, if possible (scary!) */
slouken@3657
   307
    window = SDL_GetFocusWindow();
slouken@3657
   308
    if (window) {
slouken@3657
   309
        if (SDL_GetWindowFlags(window) & SDL_WINDOW_FULLSCREEN) {
slouken@3657
   310
            SDL_MinimizeWindow(window);
slouken@3657
   311
        } else {
icculus@3670
   312
            /* !!! FIXME: ungrab the input if we're not fullscreen? */
slouken@3657
   313
            /* No need to mess with the window */
slouken@3657
   314
            window = 0;
slouken@3657
   315
        }
slouken@3657
   316
    }
slouken@3657
   317
slouken@3647
   318
    /* platform-specific UI... */
slouken@3647
   319
slouken@5086
   320
#ifdef __WIN32__
slouken@3657
   321
    state = SDL_PromptAssertion_windows(data);
slouken@3647
   322
icculus@6051
   323
#elif defined __MACOSX__ && defined SDL_VIDEO_DRIVER_COCOA
slouken@3647
   324
    /* This has to be done in an Objective-C (*.m) file, so we call out. */
slouken@3647
   325
    extern SDL_assert_state SDL_PromptAssertion_cocoa(const SDL_assert_data *);
slouken@3657
   326
    state = SDL_PromptAssertion_cocoa(data);
slouken@3647
   327
slouken@3657
   328
#else
slouken@3647
   329
    /* this is a little hacky. */
slouken@3647
   330
    for ( ; ; ) {
slouken@3647
   331
        char buf[32];
slouken@3647
   332
        fprintf(stderr, "Abort/Break/Retry/Ignore/AlwaysIgnore? [abriA] : ");
slouken@3647
   333
        fflush(stderr);
slouken@3647
   334
        if (fgets(buf, sizeof (buf), stdin) == NULL) {
slouken@3657
   335
            break;
slouken@3647
   336
        }
slouken@3647
   337
slouken@3647
   338
        if (SDL_strcmp(buf, "a") == 0) {
slouken@3657
   339
            state = SDL_ASSERTION_ABORT;
slouken@3657
   340
            break;
icculus@5547
   341
        } else if (SDL_strcmp(buf, "b") == 0) {
slouken@3657
   342
            state = SDL_ASSERTION_BREAK;
slouken@3657
   343
            break;
icculus@5547
   344
        } else if (SDL_strcmp(buf, "r") == 0) {
slouken@3657
   345
            state = SDL_ASSERTION_RETRY;
slouken@3657
   346
            break;
icculus@5547
   347
        } else if (SDL_strcmp(buf, "i") == 0) {
slouken@3657
   348
            state = SDL_ASSERTION_IGNORE;
slouken@3657
   349
            break;
icculus@5547
   350
        } else if (SDL_strcmp(buf, "A") == 0) {
slouken@3657
   351
            state = SDL_ASSERTION_ALWAYS_IGNORE;
slouken@3657
   352
            break;
slouken@3647
   353
        }
slouken@3647
   354
    }
slouken@3647
   355
#endif
slouken@3647
   356
slouken@3657
   357
    /* Re-enter fullscreen mode */
slouken@3657
   358
    if (window) {
slouken@3657
   359
        SDL_RestoreWindow(window);
slouken@3657
   360
    }
slouken@3657
   361
slouken@3657
   362
    return state;
slouken@3647
   363
}
slouken@3647
   364
slouken@3647
   365
slouken@3647
   366
SDL_assert_state
slouken@3655
   367
SDL_ReportAssertion(SDL_assert_data *data, const char *func, const char *file,
slouken@3655
   368
                    int line)
slouken@3647
   369
{
icculus@3661
   370
    static int assertion_running = 0;
icculus@3662
   371
    static SDL_SpinLock spinlock = 0;
icculus@3661
   372
    SDL_assert_state state = SDL_ASSERTION_IGNORE;
slouken@3647
   373
icculus@3662
   374
    SDL_AtomicLock(&spinlock);
icculus@3662
   375
    if (assertion_mutex == NULL) { /* never called SDL_Init()? */
icculus@3662
   376
        assertion_mutex = SDL_CreateMutex();
icculus@3662
   377
        if (assertion_mutex == NULL) {
icculus@3662
   378
            SDL_AtomicUnlock(&spinlock);
icculus@3662
   379
            return SDL_ASSERTION_IGNORE;   /* oh well, I guess. */
icculus@3662
   380
        }
icculus@3662
   381
    }
icculus@3662
   382
    SDL_AtomicUnlock(&spinlock);
icculus@3662
   383
slouken@3647
   384
    if (SDL_LockMutex(assertion_mutex) < 0) {
slouken@3647
   385
        return SDL_ASSERTION_IGNORE;   /* oh well, I guess. */
slouken@3647
   386
    }
slouken@3647
   387
slouken@3647
   388
    /* doing this because Visual C is upset over assigning in the macro. */
slouken@3647
   389
    if (data->trigger_count == 0) {
slouken@3647
   390
        data->function = func;
slouken@3655
   391
        data->filename = file;
slouken@3655
   392
        data->linenum = line;
slouken@3647
   393
    }
slouken@3647
   394
slouken@3647
   395
    SDL_AddAssertionToReport(data);
slouken@3647
   396
icculus@3661
   397
    assertion_running++;
icculus@3661
   398
    if (assertion_running > 1) {   /* assert during assert! Abort. */
icculus@3661
   399
        if (assertion_running == 2) {
icculus@3661
   400
            SDL_AbortAssertion();
icculus@3661
   401
        } else if (assertion_running == 3) {  /* Abort asserted! */
icculus@3661
   402
            SDL_ExitProcess(42);
icculus@3661
   403
        } else {
icculus@3661
   404
            while (1) { /* do nothing but spin; what else can you do?! */ }
icculus@3661
   405
        }
slouken@3647
   406
    }
slouken@3647
   407
icculus@3661
   408
    if (!data->always_ignore) {
icculus@3670
   409
        state = assertion_handler(data, assertion_userdata);
icculus@3661
   410
    }
slouken@3647
   411
slouken@3647
   412
    switch (state)
slouken@3647
   413
    {
slouken@3647
   414
        case SDL_ASSERTION_ABORT:
slouken@3647
   415
            SDL_AbortAssertion();
slouken@3647
   416
            return SDL_ASSERTION_IGNORE;  /* shouldn't return, but oh well. */
slouken@3647
   417
slouken@3647
   418
        case SDL_ASSERTION_ALWAYS_IGNORE:
slouken@3647
   419
            state = SDL_ASSERTION_IGNORE;
slouken@3647
   420
            data->always_ignore = 1;
slouken@3647
   421
            break;
slouken@3647
   422
slouken@3647
   423
        case SDL_ASSERTION_IGNORE:
slouken@3647
   424
        case SDL_ASSERTION_RETRY:
slouken@3647
   425
        case SDL_ASSERTION_BREAK:
slouken@3647
   426
            break;  /* macro handles these. */
slouken@3647
   427
    }
slouken@3647
   428
icculus@3661
   429
    assertion_running--;
slouken@3647
   430
    SDL_UnlockMutex(assertion_mutex);
slouken@3647
   431
slouken@3647
   432
    return state;
slouken@3647
   433
}
slouken@3647
   434
slouken@3647
   435
slouken@3647
   436
int SDL_AssertionsInit(void)
slouken@3647
   437
{
icculus@3664
   438
    /* this is a no-op at the moment. */
slouken@3647
   439
    return 0;
slouken@3647
   440
}
slouken@3647
   441
slouken@3647
   442
void SDL_AssertionsQuit(void)
slouken@3647
   443
{
slouken@3647
   444
    SDL_GenerateAssertionReport();
icculus@3664
   445
    if (assertion_mutex != NULL) {
icculus@3664
   446
        SDL_DestroyMutex(assertion_mutex);
icculus@3664
   447
        assertion_mutex = NULL;
icculus@3664
   448
    }
icculus@3670
   449
}
icculus@3670
   450
icculus@3670
   451
void SDL_SetAssertionHandler(SDL_AssertionHandler handler, void *userdata)
icculus@3670
   452
{
icculus@3670
   453
    if (handler != NULL) {
icculus@3670
   454
        assertion_handler = handler;
icculus@3670
   455
        assertion_userdata = userdata;
icculus@3670
   456
    } else {
icculus@3670
   457
        assertion_handler = SDL_PromptAssertion;
icculus@3670
   458
        assertion_userdata = NULL;
icculus@3670
   459
    }
icculus@3670
   460
}
icculus@3670
   461
icculus@3670
   462
const SDL_assert_data *SDL_GetAssertionReport(void)
icculus@3670
   463
{
icculus@3670
   464
    return triggered_assertions;
icculus@3670
   465
}
icculus@3670
   466
icculus@3670
   467
void SDL_ResetAssertionReport(void)
icculus@3670
   468
{
icculus@3670
   469
    SDL_assert_data *next = NULL;
icculus@5541
   470
    SDL_assert_data *item;
icculus@5541
   471
    for (item = triggered_assertions; item != NULL; item = next) {
icculus@3670
   472
        next = (SDL_assert_data *) item->next;
icculus@3670
   473
        item->always_ignore = SDL_FALSE;
icculus@3670
   474
        item->trigger_count = 0;
icculus@3670
   475
        item->next = NULL;
icculus@3670
   476
    }
icculus@3670
   477
icculus@5541
   478
    triggered_assertions = NULL;
slouken@3647
   479
}
slouken@3647
   480
slouken@3647
   481
/* vi: set ts=4 sw=4 expandtab: */