src/SDL_assert.c
author David Ludwig <dludwig@pobox.com>
Wed, 17 Oct 2012 21:43:20 -0400
changeset 8316 88f011703f39
parent 6305 601b0e251822
child 8337 4a67a3cca43d
permissions -rw-r--r--
Got a bare-bones version of SDL compiling for Windows RT. Dummy drivers are used in some places. Very little Windows-specific code (from the Win32 version of SDL) is used.
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
dludwig@8316
    29
#if defined(__WIN32__) || defined(__WINRT__)
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
{
dludwig@8316
    62
#if defined(__WIN32__) || defined(__WINRT__)
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
dludwig@8316
   216
#ifdef __WINRT__
dludwig@8316
   217
dludwig@8316
   218
static SDL_assert_state
dludwig@8316
   219
SDL_PromptAssertion_windowsrt(const SDL_assert_data *data)
dludwig@8316
   220
{
dludwig@8316
   221
    /* TODO, WinRT: implement SDL_PromptAssertion_windowsrt */
dludwig@8316
   222
    return SDL_ASSERTION_ABORT;
dludwig@8316
   223
}
dludwig@8316
   224
dludwig@8316
   225
#endif
dludwig@8316
   226
dludwig@8316
   227
slouken@3647
   228
static void SDL_AddAssertionToReport(SDL_assert_data *data)
slouken@3647
   229
{
slouken@3647
   230
    /* (data) is always a static struct defined with the assert macros, so
slouken@3647
   231
       we don't have to worry about copying or allocating them. */
icculus@5541
   232
    data->trigger_count++;
icculus@5541
   233
    if (data->trigger_count == 1) {  /* not yet added? */
slouken@3647
   234
        data->next = triggered_assertions;
slouken@3647
   235
        triggered_assertions = data;
slouken@3647
   236
    }
slouken@3647
   237
}
slouken@3647
   238
icculus@3670
   239
slouken@3647
   240
static void SDL_GenerateAssertionReport(void)
slouken@3647
   241
{
icculus@5541
   242
    const SDL_assert_data *item = triggered_assertions;
icculus@3670
   243
icculus@3670
   244
    /* only do this if the app hasn't assigned an assertion handler. */
icculus@5541
   245
    if ((item != NULL) && (assertion_handler != SDL_PromptAssertion)) {
slouken@3647
   246
        debug_print("\n\nSDL assertion report.\n");
slouken@3647
   247
        debug_print("All SDL assertions between last init/quit:\n\n");
slouken@3647
   248
icculus@5541
   249
        while (item != NULL) {
slouken@3647
   250
            debug_print(
slouken@3647
   251
                "'%s'\n"
slouken@3647
   252
                "    * %s (%s:%d)\n"
slouken@3647
   253
                "    * triggered %u time%s.\n"
slouken@3647
   254
                "    * always ignore: %s.\n",
slouken@3647
   255
                item->condition, item->function, item->filename,
slouken@3647
   256
                item->linenum, item->trigger_count,
slouken@3647
   257
                (item->trigger_count == 1) ? "" : "s",
slouken@3647
   258
                item->always_ignore ? "yes" : "no");
slouken@3647
   259
            item = item->next;
slouken@3647
   260
        }
slouken@3647
   261
        debug_print("\n");
slouken@3647
   262
icculus@3670
   263
        SDL_ResetAssertionReport();
slouken@3647
   264
    }
slouken@3647
   265
}
slouken@3647
   266
icculus@3661
   267
static void SDL_ExitProcess(int exitcode)
slouken@3647
   268
{
dludwig@8316
   269
#if defined(__WIN32__)
icculus@6305
   270
    ExitProcess(exitcode);
dludwig@8316
   271
#elif defined(__WINRT__)
dludwig@8316
   272
    exit(exitcode);
slouken@3656
   273
#else
icculus@6305
   274
    _exit(exitcode);
slouken@3647
   275
#endif
slouken@3647
   276
}
icculus@3661
   277
icculus@3661
   278
static void SDL_AbortAssertion(void)
icculus@3661
   279
{
icculus@3661
   280
    SDL_Quit();
icculus@3661
   281
    SDL_ExitProcess(42);
icculus@3661
   282
}
icculus@3661
   283
slouken@3647
   284
icculus@3670
   285
static SDL_assert_state
icculus@3670
   286
SDL_PromptAssertion(const SDL_assert_data *data, void *userdata)
slouken@3647
   287
{
slouken@3647
   288
    const char *envr;
slouken@3657
   289
    SDL_assert_state state = SDL_ASSERTION_ABORT;
slouken@3685
   290
    SDL_Window *window;
slouken@3647
   291
icculus@3670
   292
    (void) userdata;  /* unused in default handler. */
icculus@3670
   293
slouken@3647
   294
    debug_print("\n\n"
slouken@3647
   295
                "Assertion failure at %s (%s:%d), triggered %u time%s:\n"
slouken@3647
   296
                "  '%s'\n"
slouken@3647
   297
                "\n",
slouken@3647
   298
                data->function, data->filename, data->linenum,
slouken@3647
   299
                data->trigger_count, (data->trigger_count == 1) ? "" : "s",
slouken@3647
   300
                data->condition);
slouken@3647
   301
slouken@3655
   302
    /* let env. variable override, so unit tests won't block in a GUI. */
slouken@3647
   303
    envr = SDL_getenv("SDL_ASSERT");
slouken@3647
   304
    if (envr != NULL) {
slouken@3647
   305
        if (SDL_strcmp(envr, "abort") == 0) {
slouken@3647
   306
            return SDL_ASSERTION_ABORT;
slouken@3647
   307
        } else if (SDL_strcmp(envr, "break") == 0) {
slouken@3647
   308
            return SDL_ASSERTION_BREAK;
slouken@3647
   309
        } else if (SDL_strcmp(envr, "retry") == 0) {
slouken@3647
   310
            return SDL_ASSERTION_RETRY;
slouken@3647
   311
        } else if (SDL_strcmp(envr, "ignore") == 0) {
slouken@3647
   312
            return SDL_ASSERTION_IGNORE;
slouken@3647
   313
        } else if (SDL_strcmp(envr, "always_ignore") == 0) {
slouken@3647
   314
            return SDL_ASSERTION_ALWAYS_IGNORE;
slouken@3647
   315
        } else {
slouken@3647
   316
            return SDL_ASSERTION_ABORT;  /* oh well. */
slouken@3647
   317
        }
slouken@3647
   318
    }
slouken@3647
   319
slouken@3657
   320
    /* Leave fullscreen mode, if possible (scary!) */
slouken@3657
   321
    window = SDL_GetFocusWindow();
slouken@3657
   322
    if (window) {
slouken@3657
   323
        if (SDL_GetWindowFlags(window) & SDL_WINDOW_FULLSCREEN) {
slouken@3657
   324
            SDL_MinimizeWindow(window);
slouken@3657
   325
        } else {
icculus@3670
   326
            /* !!! FIXME: ungrab the input if we're not fullscreen? */
slouken@3657
   327
            /* No need to mess with the window */
slouken@3657
   328
            window = 0;
slouken@3657
   329
        }
slouken@3657
   330
    }
slouken@3657
   331
slouken@3647
   332
    /* platform-specific UI... */
slouken@3647
   333
dludwig@8316
   334
#if defined(__WIN32__)
slouken@3657
   335
    state = SDL_PromptAssertion_windows(data);
slouken@3647
   336
dludwig@8316
   337
#elif defined(__WINRT__)
dludwig@8316
   338
    state = SDL_PromptAssertion_windowsrt(data);
dludwig@8316
   339
icculus@6051
   340
#elif defined __MACOSX__ && defined SDL_VIDEO_DRIVER_COCOA
slouken@3647
   341
    /* This has to be done in an Objective-C (*.m) file, so we call out. */
slouken@3647
   342
    extern SDL_assert_state SDL_PromptAssertion_cocoa(const SDL_assert_data *);
slouken@3657
   343
    state = SDL_PromptAssertion_cocoa(data);
slouken@3647
   344
slouken@3657
   345
#else
slouken@3647
   346
    /* this is a little hacky. */
slouken@3647
   347
    for ( ; ; ) {
slouken@3647
   348
        char buf[32];
slouken@3647
   349
        fprintf(stderr, "Abort/Break/Retry/Ignore/AlwaysIgnore? [abriA] : ");
slouken@3647
   350
        fflush(stderr);
slouken@3647
   351
        if (fgets(buf, sizeof (buf), stdin) == NULL) {
slouken@3657
   352
            break;
slouken@3647
   353
        }
slouken@3647
   354
slouken@3647
   355
        if (SDL_strcmp(buf, "a") == 0) {
slouken@3657
   356
            state = SDL_ASSERTION_ABORT;
slouken@3657
   357
            break;
icculus@5547
   358
        } else if (SDL_strcmp(buf, "b") == 0) {
slouken@3657
   359
            state = SDL_ASSERTION_BREAK;
slouken@3657
   360
            break;
icculus@5547
   361
        } else if (SDL_strcmp(buf, "r") == 0) {
slouken@3657
   362
            state = SDL_ASSERTION_RETRY;
slouken@3657
   363
            break;
icculus@5547
   364
        } else if (SDL_strcmp(buf, "i") == 0) {
slouken@3657
   365
            state = SDL_ASSERTION_IGNORE;
slouken@3657
   366
            break;
icculus@5547
   367
        } else if (SDL_strcmp(buf, "A") == 0) {
slouken@3657
   368
            state = SDL_ASSERTION_ALWAYS_IGNORE;
slouken@3657
   369
            break;
slouken@3647
   370
        }
slouken@3647
   371
    }
slouken@3647
   372
#endif
slouken@3647
   373
slouken@3657
   374
    /* Re-enter fullscreen mode */
slouken@3657
   375
    if (window) {
slouken@3657
   376
        SDL_RestoreWindow(window);
slouken@3657
   377
    }
slouken@3657
   378
slouken@3657
   379
    return state;
slouken@3647
   380
}
slouken@3647
   381
slouken@3647
   382
slouken@3647
   383
SDL_assert_state
slouken@3655
   384
SDL_ReportAssertion(SDL_assert_data *data, const char *func, const char *file,
slouken@3655
   385
                    int line)
slouken@3647
   386
{
icculus@3661
   387
    static int assertion_running = 0;
icculus@3662
   388
    static SDL_SpinLock spinlock = 0;
icculus@3661
   389
    SDL_assert_state state = SDL_ASSERTION_IGNORE;
slouken@3647
   390
icculus@3662
   391
    SDL_AtomicLock(&spinlock);
icculus@3662
   392
    if (assertion_mutex == NULL) { /* never called SDL_Init()? */
icculus@3662
   393
        assertion_mutex = SDL_CreateMutex();
icculus@3662
   394
        if (assertion_mutex == NULL) {
icculus@3662
   395
            SDL_AtomicUnlock(&spinlock);
icculus@3662
   396
            return SDL_ASSERTION_IGNORE;   /* oh well, I guess. */
icculus@3662
   397
        }
icculus@3662
   398
    }
icculus@3662
   399
    SDL_AtomicUnlock(&spinlock);
icculus@3662
   400
slouken@3647
   401
    if (SDL_LockMutex(assertion_mutex) < 0) {
slouken@3647
   402
        return SDL_ASSERTION_IGNORE;   /* oh well, I guess. */
slouken@3647
   403
    }
slouken@3647
   404
slouken@3647
   405
    /* doing this because Visual C is upset over assigning in the macro. */
slouken@3647
   406
    if (data->trigger_count == 0) {
slouken@3647
   407
        data->function = func;
slouken@3655
   408
        data->filename = file;
slouken@3655
   409
        data->linenum = line;
slouken@3647
   410
    }
slouken@3647
   411
slouken@3647
   412
    SDL_AddAssertionToReport(data);
slouken@3647
   413
icculus@3661
   414
    assertion_running++;
icculus@3661
   415
    if (assertion_running > 1) {   /* assert during assert! Abort. */
icculus@3661
   416
        if (assertion_running == 2) {
icculus@3661
   417
            SDL_AbortAssertion();
icculus@3661
   418
        } else if (assertion_running == 3) {  /* Abort asserted! */
icculus@3661
   419
            SDL_ExitProcess(42);
icculus@3661
   420
        } else {
icculus@3661
   421
            while (1) { /* do nothing but spin; what else can you do?! */ }
icculus@3661
   422
        }
slouken@3647
   423
    }
slouken@3647
   424
icculus@3661
   425
    if (!data->always_ignore) {
icculus@3670
   426
        state = assertion_handler(data, assertion_userdata);
icculus@3661
   427
    }
slouken@3647
   428
slouken@3647
   429
    switch (state)
slouken@3647
   430
    {
slouken@3647
   431
        case SDL_ASSERTION_ABORT:
slouken@3647
   432
            SDL_AbortAssertion();
slouken@3647
   433
            return SDL_ASSERTION_IGNORE;  /* shouldn't return, but oh well. */
slouken@3647
   434
slouken@3647
   435
        case SDL_ASSERTION_ALWAYS_IGNORE:
slouken@3647
   436
            state = SDL_ASSERTION_IGNORE;
slouken@3647
   437
            data->always_ignore = 1;
slouken@3647
   438
            break;
slouken@3647
   439
slouken@3647
   440
        case SDL_ASSERTION_IGNORE:
slouken@3647
   441
        case SDL_ASSERTION_RETRY:
slouken@3647
   442
        case SDL_ASSERTION_BREAK:
slouken@3647
   443
            break;  /* macro handles these. */
slouken@3647
   444
    }
slouken@3647
   445
icculus@3661
   446
    assertion_running--;
slouken@3647
   447
    SDL_UnlockMutex(assertion_mutex);
slouken@3647
   448
slouken@3647
   449
    return state;
slouken@3647
   450
}
slouken@3647
   451
slouken@3647
   452
slouken@3647
   453
int SDL_AssertionsInit(void)
slouken@3647
   454
{
icculus@3664
   455
    /* this is a no-op at the moment. */
slouken@3647
   456
    return 0;
slouken@3647
   457
}
slouken@3647
   458
slouken@3647
   459
void SDL_AssertionsQuit(void)
slouken@3647
   460
{
slouken@3647
   461
    SDL_GenerateAssertionReport();
icculus@3664
   462
    if (assertion_mutex != NULL) {
icculus@3664
   463
        SDL_DestroyMutex(assertion_mutex);
icculus@3664
   464
        assertion_mutex = NULL;
icculus@3664
   465
    }
icculus@3670
   466
}
icculus@3670
   467
icculus@3670
   468
void SDL_SetAssertionHandler(SDL_AssertionHandler handler, void *userdata)
icculus@3670
   469
{
icculus@3670
   470
    if (handler != NULL) {
icculus@3670
   471
        assertion_handler = handler;
icculus@3670
   472
        assertion_userdata = userdata;
icculus@3670
   473
    } else {
icculus@3670
   474
        assertion_handler = SDL_PromptAssertion;
icculus@3670
   475
        assertion_userdata = NULL;
icculus@3670
   476
    }
icculus@3670
   477
}
icculus@3670
   478
icculus@3670
   479
const SDL_assert_data *SDL_GetAssertionReport(void)
icculus@3670
   480
{
icculus@3670
   481
    return triggered_assertions;
icculus@3670
   482
}
icculus@3670
   483
icculus@3670
   484
void SDL_ResetAssertionReport(void)
icculus@3670
   485
{
icculus@3670
   486
    SDL_assert_data *next = NULL;
icculus@5541
   487
    SDL_assert_data *item;
icculus@5541
   488
    for (item = triggered_assertions; item != NULL; item = next) {
icculus@3670
   489
        next = (SDL_assert_data *) item->next;
icculus@3670
   490
        item->always_ignore = SDL_FALSE;
icculus@3670
   491
        item->trigger_count = 0;
icculus@3670
   492
        item->next = NULL;
icculus@3670
   493
    }
icculus@3670
   494
icculus@5541
   495
    triggered_assertions = NULL;
slouken@3647
   496
}
slouken@3647
   497
slouken@3647
   498
/* vi: set ts=4 sw=4 expandtab: */