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