Mercurial > sdl-ios-xcode
annotate src/SDL_assert.c @ 3647:c5925cd41955
First pass at Ryan's assertion code, minor tweaks to come.
author | Sam Lantinga <slouken@libsdl.org> |
---|---|
date | Wed, 13 Jan 2010 06:47:17 +0000 |
parents | |
children | a9d830c05998 |
rev | line source |
---|---|
3647
c5925cd41955
First pass at Ryan's assertion code, minor tweaks to come.
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
1 /* |
c5925cd41955
First pass at Ryan's assertion code, minor tweaks to come.
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
2 SDL - Simple DirectMedia Layer |
c5925cd41955
First pass at Ryan's assertion code, minor tweaks to come.
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
3 Copyright (C) 1997-2009 Sam Lantinga |
c5925cd41955
First pass at Ryan's assertion code, minor tweaks to come.
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
4 |
c5925cd41955
First pass at Ryan's assertion code, minor tweaks to come.
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
5 This library is free software; you can redistribute it and/or |
c5925cd41955
First pass at Ryan's assertion code, minor tweaks to come.
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
6 modify it under the terms of the GNU Lesser General Public |
c5925cd41955
First pass at Ryan's assertion code, minor tweaks to come.
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
7 License as published by the Free Software Foundation; either |
c5925cd41955
First pass at Ryan's assertion code, minor tweaks to come.
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
8 version 2.1 of the License, or (at your option) any later version. |
c5925cd41955
First pass at Ryan's assertion code, minor tweaks to come.
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
9 |
c5925cd41955
First pass at Ryan's assertion code, minor tweaks to come.
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
10 This library is distributed in the hope that it will be useful, |
c5925cd41955
First pass at Ryan's assertion code, minor tweaks to come.
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
11 but WITHOUT ANY WARRANTY; without even the implied warranty of |
c5925cd41955
First pass at Ryan's assertion code, minor tweaks to come.
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
c5925cd41955
First pass at Ryan's assertion code, minor tweaks to come.
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
13 Lesser General Public License for more details. |
c5925cd41955
First pass at Ryan's assertion code, minor tweaks to come.
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
14 |
c5925cd41955
First pass at Ryan's assertion code, minor tweaks to come.
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
15 You should have received a copy of the GNU Lesser General Public |
c5925cd41955
First pass at Ryan's assertion code, minor tweaks to come.
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
16 License along with this library; if not, write to the Free Software |
c5925cd41955
First pass at Ryan's assertion code, minor tweaks to come.
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
17 Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA |
c5925cd41955
First pass at Ryan's assertion code, minor tweaks to come.
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
18 |
c5925cd41955
First pass at Ryan's assertion code, minor tweaks to come.
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
19 Sam Lantinga |
c5925cd41955
First pass at Ryan's assertion code, minor tweaks to come.
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
20 slouken@libsdl.org |
c5925cd41955
First pass at Ryan's assertion code, minor tweaks to come.
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
21 */ |
c5925cd41955
First pass at Ryan's assertion code, minor tweaks to come.
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
22 |
c5925cd41955
First pass at Ryan's assertion code, minor tweaks to come.
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
23 #include "SDL_assert.h" |
c5925cd41955
First pass at Ryan's assertion code, minor tweaks to come.
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
24 #include "SDL.h" |
c5925cd41955
First pass at Ryan's assertion code, minor tweaks to come.
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
25 |
c5925cd41955
First pass at Ryan's assertion code, minor tweaks to come.
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
26 #if (SDL_ASSERT_LEVEL > 0) |
c5925cd41955
First pass at Ryan's assertion code, minor tweaks to come.
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
27 |
c5925cd41955
First pass at Ryan's assertion code, minor tweaks to come.
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
28 #ifdef _WINDOWS |
c5925cd41955
First pass at Ryan's assertion code, minor tweaks to come.
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
29 #define WIN32_LEAN_AND_MEAN 1 |
c5925cd41955
First pass at Ryan's assertion code, minor tweaks to come.
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
30 #include <windows.h> |
c5925cd41955
First pass at Ryan's assertion code, minor tweaks to come.
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
31 #else /* fprintf, _exit(), etc. */ |
c5925cd41955
First pass at Ryan's assertion code, minor tweaks to come.
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
32 #include <stdio.h> |
c5925cd41955
First pass at Ryan's assertion code, minor tweaks to come.
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
33 #include <stdlib.h> |
c5925cd41955
First pass at Ryan's assertion code, minor tweaks to come.
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
34 #endif |
c5925cd41955
First pass at Ryan's assertion code, minor tweaks to come.
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
35 |
c5925cd41955
First pass at Ryan's assertion code, minor tweaks to come.
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
36 /* We can keep all triggered assertions in a singly-linked list so we can |
c5925cd41955
First pass at Ryan's assertion code, minor tweaks to come.
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
37 * generate a report later. |
c5925cd41955
First pass at Ryan's assertion code, minor tweaks to come.
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
38 */ |
c5925cd41955
First pass at Ryan's assertion code, minor tweaks to come.
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
39 #if !SDL_ASSERTION_REPORT_DISABLED |
c5925cd41955
First pass at Ryan's assertion code, minor tweaks to come.
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
40 static SDL_assert_data assertion_list_terminator = { 0, 0, 0, 0, 0, 0, 0 }; |
c5925cd41955
First pass at Ryan's assertion code, minor tweaks to come.
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
41 static SDL_assert_data *triggered_assertions = &assertion_list_terminator; |
c5925cd41955
First pass at Ryan's assertion code, minor tweaks to come.
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
42 #endif |
c5925cd41955
First pass at Ryan's assertion code, minor tweaks to come.
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
43 |
c5925cd41955
First pass at Ryan's assertion code, minor tweaks to come.
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
44 static void |
c5925cd41955
First pass at Ryan's assertion code, minor tweaks to come.
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
45 debug_print(const char *fmt, ...) |
c5925cd41955
First pass at Ryan's assertion code, minor tweaks to come.
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
46 //#ifdef __GNUC__ |
c5925cd41955
First pass at Ryan's assertion code, minor tweaks to come.
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
47 //__attribute__((format (printf, 1, 2))) |
c5925cd41955
First pass at Ryan's assertion code, minor tweaks to come.
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
48 //#endif |
c5925cd41955
First pass at Ryan's assertion code, minor tweaks to come.
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
49 { |
c5925cd41955
First pass at Ryan's assertion code, minor tweaks to come.
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
50 #ifdef _WINDOWS |
c5925cd41955
First pass at Ryan's assertion code, minor tweaks to come.
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
51 /* Format into a buffer for OutputDebugStringA(). */ |
c5925cd41955
First pass at Ryan's assertion code, minor tweaks to come.
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
52 char buf[1024]; |
c5925cd41955
First pass at Ryan's assertion code, minor tweaks to come.
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
53 char *startptr; |
c5925cd41955
First pass at Ryan's assertion code, minor tweaks to come.
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
54 char *ptr; |
c5925cd41955
First pass at Ryan's assertion code, minor tweaks to come.
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
55 int len; |
c5925cd41955
First pass at Ryan's assertion code, minor tweaks to come.
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
56 va_list ap; |
c5925cd41955
First pass at Ryan's assertion code, minor tweaks to come.
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
57 va_start(ap, fmt); |
c5925cd41955
First pass at Ryan's assertion code, minor tweaks to come.
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
58 len = (int) SDL_vsnprintf(buf, sizeof (buf), fmt, ap); |
c5925cd41955
First pass at Ryan's assertion code, minor tweaks to come.
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
59 va_end(ap); |
c5925cd41955
First pass at Ryan's assertion code, minor tweaks to come.
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
60 |
c5925cd41955
First pass at Ryan's assertion code, minor tweaks to come.
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
61 /* Visual C's vsnprintf() may not null-terminate the buffer. */ |
c5925cd41955
First pass at Ryan's assertion code, minor tweaks to come.
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
62 if ((len >= sizeof (buf)) || (len < 0)) { |
c5925cd41955
First pass at Ryan's assertion code, minor tweaks to come.
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
63 buf[sizeof (buf) - 1] = '\0'; |
c5925cd41955
First pass at Ryan's assertion code, minor tweaks to come.
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
64 } |
c5925cd41955
First pass at Ryan's assertion code, minor tweaks to come.
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
65 |
c5925cd41955
First pass at Ryan's assertion code, minor tweaks to come.
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
66 /* Write it, sorting out the Unix newlines... */ |
c5925cd41955
First pass at Ryan's assertion code, minor tweaks to come.
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
67 startptr = buf; |
c5925cd41955
First pass at Ryan's assertion code, minor tweaks to come.
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
68 for (ptr = startptr; *ptr; ptr++) { |
c5925cd41955
First pass at Ryan's assertion code, minor tweaks to come.
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
69 if (*ptr == '\n') { |
c5925cd41955
First pass at Ryan's assertion code, minor tweaks to come.
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
70 *ptr = '\0'; |
c5925cd41955
First pass at Ryan's assertion code, minor tweaks to come.
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
71 OutputDebugStringA(startptr); |
c5925cd41955
First pass at Ryan's assertion code, minor tweaks to come.
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
72 OutputDebugStringA("\r\n"); |
c5925cd41955
First pass at Ryan's assertion code, minor tweaks to come.
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
73 startptr = ptr+1; |
c5925cd41955
First pass at Ryan's assertion code, minor tweaks to come.
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
74 } |
c5925cd41955
First pass at Ryan's assertion code, minor tweaks to come.
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
75 } |
c5925cd41955
First pass at Ryan's assertion code, minor tweaks to come.
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
76 |
c5925cd41955
First pass at Ryan's assertion code, minor tweaks to come.
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
77 /* catch that last piece if it didn't have a newline... */ |
c5925cd41955
First pass at Ryan's assertion code, minor tweaks to come.
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
78 if (startptr != ptr) { |
c5925cd41955
First pass at Ryan's assertion code, minor tweaks to come.
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
79 OutputDebugStringA(startptr); |
c5925cd41955
First pass at Ryan's assertion code, minor tweaks to come.
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
80 } |
c5925cd41955
First pass at Ryan's assertion code, minor tweaks to come.
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
81 #else |
c5925cd41955
First pass at Ryan's assertion code, minor tweaks to come.
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
82 /* Unix has it easy. Just dump it to stderr. */ |
c5925cd41955
First pass at Ryan's assertion code, minor tweaks to come.
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
83 va_list ap; |
c5925cd41955
First pass at Ryan's assertion code, minor tweaks to come.
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
84 va_start(ap, fmt); |
c5925cd41955
First pass at Ryan's assertion code, minor tweaks to come.
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
85 fprintf(stderr, fmt, ap); |
c5925cd41955
First pass at Ryan's assertion code, minor tweaks to come.
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
86 va_end(ap); |
c5925cd41955
First pass at Ryan's assertion code, minor tweaks to come.
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
87 fflush(stderr); |
c5925cd41955
First pass at Ryan's assertion code, minor tweaks to come.
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
88 #endif |
c5925cd41955
First pass at Ryan's assertion code, minor tweaks to come.
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
89 } |
c5925cd41955
First pass at Ryan's assertion code, minor tweaks to come.
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
90 |
c5925cd41955
First pass at Ryan's assertion code, minor tweaks to come.
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
91 |
c5925cd41955
First pass at Ryan's assertion code, minor tweaks to come.
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
92 #ifdef _WINDOWS |
c5925cd41955
First pass at Ryan's assertion code, minor tweaks to come.
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
93 static SDL_assert_state SDL_Windows_AssertChoice = SDL_ASSERTION_ABORT; |
c5925cd41955
First pass at Ryan's assertion code, minor tweaks to come.
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
94 static const SDL_assert_data *SDL_Windows_AssertData = NULL; |
c5925cd41955
First pass at Ryan's assertion code, minor tweaks to come.
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
95 |
c5925cd41955
First pass at Ryan's assertion code, minor tweaks to come.
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
96 static LRESULT CALLBACK |
c5925cd41955
First pass at Ryan's assertion code, minor tweaks to come.
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
97 SDL_Assertion_WndProc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam) |
c5925cd41955
First pass at Ryan's assertion code, minor tweaks to come.
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
98 { |
c5925cd41955
First pass at Ryan's assertion code, minor tweaks to come.
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
99 switch (msg) |
c5925cd41955
First pass at Ryan's assertion code, minor tweaks to come.
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
100 { |
c5925cd41955
First pass at Ryan's assertion code, minor tweaks to come.
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
101 case WM_CREATE: |
c5925cd41955
First pass at Ryan's assertion code, minor tweaks to come.
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
102 { |
c5925cd41955
First pass at Ryan's assertion code, minor tweaks to come.
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
103 /* !!! FIXME: all this code stinks. */ |
c5925cd41955
First pass at Ryan's assertion code, minor tweaks to come.
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
104 const SDL_assert_data *data = SDL_Windows_AssertData; |
c5925cd41955
First pass at Ryan's assertion code, minor tweaks to come.
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
105 char buf[1024]; |
c5925cd41955
First pass at Ryan's assertion code, minor tweaks to come.
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
106 const int w = 100; |
c5925cd41955
First pass at Ryan's assertion code, minor tweaks to come.
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
107 const int h = 25; |
c5925cd41955
First pass at Ryan's assertion code, minor tweaks to come.
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
108 const int gap = 10; |
c5925cd41955
First pass at Ryan's assertion code, minor tweaks to come.
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
109 int x = gap; |
c5925cd41955
First pass at Ryan's assertion code, minor tweaks to come.
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
110 int y = 50; |
c5925cd41955
First pass at Ryan's assertion code, minor tweaks to come.
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
111 int len; |
c5925cd41955
First pass at Ryan's assertion code, minor tweaks to come.
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
112 int i; |
c5925cd41955
First pass at Ryan's assertion code, minor tweaks to come.
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
113 static const struct { |
c5925cd41955
First pass at Ryan's assertion code, minor tweaks to come.
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
114 const char *name; |
c5925cd41955
First pass at Ryan's assertion code, minor tweaks to come.
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
115 SDL_assert_state state; |
c5925cd41955
First pass at Ryan's assertion code, minor tweaks to come.
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
116 } buttons[] = { |
c5925cd41955
First pass at Ryan's assertion code, minor tweaks to come.
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
117 {"Abort", SDL_ASSERTION_ABORT }, |
c5925cd41955
First pass at Ryan's assertion code, minor tweaks to come.
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
118 {"Break", SDL_ASSERTION_BREAK }, |
c5925cd41955
First pass at Ryan's assertion code, minor tweaks to come.
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
119 {"Retry", SDL_ASSERTION_RETRY }, |
c5925cd41955
First pass at Ryan's assertion code, minor tweaks to come.
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
120 {"Ignore", SDL_ASSERTION_IGNORE }, |
c5925cd41955
First pass at Ryan's assertion code, minor tweaks to come.
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
121 {"Always Ignore", SDL_ASSERTION_ALWAYS_IGNORE }, |
c5925cd41955
First pass at Ryan's assertion code, minor tweaks to come.
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
122 }; |
c5925cd41955
First pass at Ryan's assertion code, minor tweaks to come.
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
123 |
c5925cd41955
First pass at Ryan's assertion code, minor tweaks to come.
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
124 len = (int) SDL_snprintf(buf, sizeof (buf), |
c5925cd41955
First pass at Ryan's assertion code, minor tweaks to come.
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
125 "Assertion failure at %s (%s:%d), triggered %u time%s:\r\n '%s'", |
c5925cd41955
First pass at Ryan's assertion code, minor tweaks to come.
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
126 data->function, data->filename, data->linenum, |
c5925cd41955
First pass at Ryan's assertion code, minor tweaks to come.
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
127 data->trigger_count, (data->trigger_count == 1) ? "" : "s", |
c5925cd41955
First pass at Ryan's assertion code, minor tweaks to come.
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
128 data->condition); |
c5925cd41955
First pass at Ryan's assertion code, minor tweaks to come.
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
129 if ((len < 0) || (len >= sizeof (buf))) { |
c5925cd41955
First pass at Ryan's assertion code, minor tweaks to come.
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
130 buf[sizeof (buf) - 1] = '\0'; |
c5925cd41955
First pass at Ryan's assertion code, minor tweaks to come.
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
131 } |
c5925cd41955
First pass at Ryan's assertion code, minor tweaks to come.
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
132 |
c5925cd41955
First pass at Ryan's assertion code, minor tweaks to come.
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
133 CreateWindowA("STATIC", buf, |
c5925cd41955
First pass at Ryan's assertion code, minor tweaks to come.
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
134 WS_VISIBLE | WS_CHILD | SS_LEFT, |
c5925cd41955
First pass at Ryan's assertion code, minor tweaks to come.
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
135 x, y, 550, 100, |
c5925cd41955
First pass at Ryan's assertion code, minor tweaks to come.
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
136 hwnd, (HMENU) 1, NULL, NULL); |
c5925cd41955
First pass at Ryan's assertion code, minor tweaks to come.
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
137 y += 110; |
c5925cd41955
First pass at Ryan's assertion code, minor tweaks to come.
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
138 |
c5925cd41955
First pass at Ryan's assertion code, minor tweaks to come.
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
139 for (i = 0; i < (sizeof (buttons) / sizeof (buttons[0])); i++) { |
c5925cd41955
First pass at Ryan's assertion code, minor tweaks to come.
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
140 CreateWindowA("BUTTON", buttons[i].name, |
c5925cd41955
First pass at Ryan's assertion code, minor tweaks to come.
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
141 WS_VISIBLE | WS_CHILD, |
c5925cd41955
First pass at Ryan's assertion code, minor tweaks to come.
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
142 x, y, w, h, |
c5925cd41955
First pass at Ryan's assertion code, minor tweaks to come.
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
143 hwnd, (HMENU) buttons[i].state, NULL, NULL); |
c5925cd41955
First pass at Ryan's assertion code, minor tweaks to come.
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
144 x += w + gap; |
c5925cd41955
First pass at Ryan's assertion code, minor tweaks to come.
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
145 } |
c5925cd41955
First pass at Ryan's assertion code, minor tweaks to come.
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
146 break; |
c5925cd41955
First pass at Ryan's assertion code, minor tweaks to come.
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
147 } |
c5925cd41955
First pass at Ryan's assertion code, minor tweaks to come.
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
148 |
c5925cd41955
First pass at Ryan's assertion code, minor tweaks to come.
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
149 case WM_COMMAND: |
c5925cd41955
First pass at Ryan's assertion code, minor tweaks to come.
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
150 SDL_Windows_AssertChoice = ((SDL_assert_state) (LOWORD(wParam))); |
c5925cd41955
First pass at Ryan's assertion code, minor tweaks to come.
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
151 SDL_Windows_AssertData = NULL; |
c5925cd41955
First pass at Ryan's assertion code, minor tweaks to come.
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
152 break; |
c5925cd41955
First pass at Ryan's assertion code, minor tweaks to come.
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
153 |
c5925cd41955
First pass at Ryan's assertion code, minor tweaks to come.
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
154 case WM_DESTROY: |
c5925cd41955
First pass at Ryan's assertion code, minor tweaks to come.
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
155 SDL_Windows_AssertData = NULL; |
c5925cd41955
First pass at Ryan's assertion code, minor tweaks to come.
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
156 break; |
c5925cd41955
First pass at Ryan's assertion code, minor tweaks to come.
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
157 } |
c5925cd41955
First pass at Ryan's assertion code, minor tweaks to come.
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
158 |
c5925cd41955
First pass at Ryan's assertion code, minor tweaks to come.
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
159 return DefWindowProc(hwnd, msg, wParam, lParam); |
c5925cd41955
First pass at Ryan's assertion code, minor tweaks to come.
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
160 } |
c5925cd41955
First pass at Ryan's assertion code, minor tweaks to come.
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
161 |
c5925cd41955
First pass at Ryan's assertion code, minor tweaks to come.
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
162 static SDL_assert_state |
c5925cd41955
First pass at Ryan's assertion code, minor tweaks to come.
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
163 SDL_PromptAssertion_windows(const SDL_assert_data *data) |
c5925cd41955
First pass at Ryan's assertion code, minor tweaks to come.
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
164 { |
c5925cd41955
First pass at Ryan's assertion code, minor tweaks to come.
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
165 HINSTANCE hInstance = 0; /* !!! FIXME? */ |
c5925cd41955
First pass at Ryan's assertion code, minor tweaks to come.
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
166 HWND hwnd; |
c5925cd41955
First pass at Ryan's assertion code, minor tweaks to come.
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
167 MSG msg; |
c5925cd41955
First pass at Ryan's assertion code, minor tweaks to come.
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
168 WNDCLASS wc = {0}; |
c5925cd41955
First pass at Ryan's assertion code, minor tweaks to come.
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
169 |
c5925cd41955
First pass at Ryan's assertion code, minor tweaks to come.
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
170 SDL_Windows_AssertChoice = SDL_ASSERTION_ABORT; |
c5925cd41955
First pass at Ryan's assertion code, minor tweaks to come.
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
171 SDL_Windows_AssertData = data; |
c5925cd41955
First pass at Ryan's assertion code, minor tweaks to come.
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
172 |
c5925cd41955
First pass at Ryan's assertion code, minor tweaks to come.
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
173 wc.lpszClassName = TEXT("SDL_assert"); |
c5925cd41955
First pass at Ryan's assertion code, minor tweaks to come.
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
174 wc.hInstance = hInstance ; |
c5925cd41955
First pass at Ryan's assertion code, minor tweaks to come.
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
175 wc.hbrBackground = GetSysColorBrush(COLOR_3DFACE); |
c5925cd41955
First pass at Ryan's assertion code, minor tweaks to come.
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
176 wc.lpfnWndProc = SDL_Assertion_WndProc; |
c5925cd41955
First pass at Ryan's assertion code, minor tweaks to come.
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
177 wc.hCursor = LoadCursor(0, IDC_ARROW); |
c5925cd41955
First pass at Ryan's assertion code, minor tweaks to come.
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
178 |
c5925cd41955
First pass at Ryan's assertion code, minor tweaks to come.
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
179 RegisterClass(&wc); |
c5925cd41955
First pass at Ryan's assertion code, minor tweaks to come.
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
180 hwnd = CreateWindow(wc.lpszClassName, TEXT("SDL assertion failure"), |
c5925cd41955
First pass at Ryan's assertion code, minor tweaks to come.
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
181 WS_OVERLAPPEDWINDOW | WS_VISIBLE, |
c5925cd41955
First pass at Ryan's assertion code, minor tweaks to come.
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
182 150, 150, 570, 260, 0, 0, hInstance, 0); |
c5925cd41955
First pass at Ryan's assertion code, minor tweaks to come.
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
183 |
c5925cd41955
First pass at Ryan's assertion code, minor tweaks to come.
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
184 while (GetMessage(&msg, NULL, 0, 0) && (SDL_Windows_AssertData != NULL)) { |
c5925cd41955
First pass at Ryan's assertion code, minor tweaks to come.
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
185 TranslateMessage(&msg); |
c5925cd41955
First pass at Ryan's assertion code, minor tweaks to come.
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
186 DispatchMessage(&msg); |
c5925cd41955
First pass at Ryan's assertion code, minor tweaks to come.
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
187 } |
c5925cd41955
First pass at Ryan's assertion code, minor tweaks to come.
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
188 |
c5925cd41955
First pass at Ryan's assertion code, minor tweaks to come.
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
189 DestroyWindow(hwnd); |
c5925cd41955
First pass at Ryan's assertion code, minor tweaks to come.
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
190 UnregisterClass(wc.lpszClassName, hInstance); |
c5925cd41955
First pass at Ryan's assertion code, minor tweaks to come.
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
191 return SDL_Windows_AssertChoice; |
c5925cd41955
First pass at Ryan's assertion code, minor tweaks to come.
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
192 } |
c5925cd41955
First pass at Ryan's assertion code, minor tweaks to come.
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
193 #endif |
c5925cd41955
First pass at Ryan's assertion code, minor tweaks to come.
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
194 |
c5925cd41955
First pass at Ryan's assertion code, minor tweaks to come.
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
195 |
c5925cd41955
First pass at Ryan's assertion code, minor tweaks to come.
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
196 static void SDL_AddAssertionToReport(SDL_assert_data *data) |
c5925cd41955
First pass at Ryan's assertion code, minor tweaks to come.
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
197 { |
c5925cd41955
First pass at Ryan's assertion code, minor tweaks to come.
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
198 #if !SDL_ASSERTION_REPORT_DISABLED |
c5925cd41955
First pass at Ryan's assertion code, minor tweaks to come.
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
199 /* (data) is always a static struct defined with the assert macros, so |
c5925cd41955
First pass at Ryan's assertion code, minor tweaks to come.
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
200 we don't have to worry about copying or allocating them. */ |
c5925cd41955
First pass at Ryan's assertion code, minor tweaks to come.
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
201 if (data->next == NULL) { /* not yet added? */ |
c5925cd41955
First pass at Ryan's assertion code, minor tweaks to come.
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
202 data->next = triggered_assertions; |
c5925cd41955
First pass at Ryan's assertion code, minor tweaks to come.
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
203 triggered_assertions = data; |
c5925cd41955
First pass at Ryan's assertion code, minor tweaks to come.
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
204 } |
c5925cd41955
First pass at Ryan's assertion code, minor tweaks to come.
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
205 #endif |
c5925cd41955
First pass at Ryan's assertion code, minor tweaks to come.
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
206 } |
c5925cd41955
First pass at Ryan's assertion code, minor tweaks to come.
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
207 |
c5925cd41955
First pass at Ryan's assertion code, minor tweaks to come.
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
208 static void SDL_GenerateAssertionReport(void) |
c5925cd41955
First pass at Ryan's assertion code, minor tweaks to come.
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
209 { |
c5925cd41955
First pass at Ryan's assertion code, minor tweaks to come.
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
210 #if !SDL_ASSERTION_REPORT_DISABLED |
c5925cd41955
First pass at Ryan's assertion code, minor tweaks to come.
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
211 if (triggered_assertions != &assertion_list_terminator) |
c5925cd41955
First pass at Ryan's assertion code, minor tweaks to come.
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
212 { |
c5925cd41955
First pass at Ryan's assertion code, minor tweaks to come.
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
213 SDL_assert_data *item = triggered_assertions; |
c5925cd41955
First pass at Ryan's assertion code, minor tweaks to come.
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
214 |
c5925cd41955
First pass at Ryan's assertion code, minor tweaks to come.
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
215 debug_print("\n\nSDL assertion report.\n"); |
c5925cd41955
First pass at Ryan's assertion code, minor tweaks to come.
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
216 debug_print("All SDL assertions between last init/quit:\n\n"); |
c5925cd41955
First pass at Ryan's assertion code, minor tweaks to come.
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
217 |
c5925cd41955
First pass at Ryan's assertion code, minor tweaks to come.
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
218 while (item != &assertion_list_terminator) { |
c5925cd41955
First pass at Ryan's assertion code, minor tweaks to come.
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
219 debug_print( |
c5925cd41955
First pass at Ryan's assertion code, minor tweaks to come.
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
220 "'%s'\n" |
c5925cd41955
First pass at Ryan's assertion code, minor tweaks to come.
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
221 " * %s (%s:%d)\n" |
c5925cd41955
First pass at Ryan's assertion code, minor tweaks to come.
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
222 " * triggered %u time%s.\n" |
c5925cd41955
First pass at Ryan's assertion code, minor tweaks to come.
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
223 " * always ignore: %s.\n", |
c5925cd41955
First pass at Ryan's assertion code, minor tweaks to come.
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
224 item->condition, item->function, item->filename, |
c5925cd41955
First pass at Ryan's assertion code, minor tweaks to come.
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
225 item->linenum, item->trigger_count, |
c5925cd41955
First pass at Ryan's assertion code, minor tweaks to come.
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
226 (item->trigger_count == 1) ? "" : "s", |
c5925cd41955
First pass at Ryan's assertion code, minor tweaks to come.
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
227 item->always_ignore ? "yes" : "no"); |
c5925cd41955
First pass at Ryan's assertion code, minor tweaks to come.
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
228 item = item->next; |
c5925cd41955
First pass at Ryan's assertion code, minor tweaks to come.
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
229 } |
c5925cd41955
First pass at Ryan's assertion code, minor tweaks to come.
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
230 debug_print("\n"); |
c5925cd41955
First pass at Ryan's assertion code, minor tweaks to come.
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
231 |
c5925cd41955
First pass at Ryan's assertion code, minor tweaks to come.
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
232 triggered_assertions = &assertion_list_terminator; |
c5925cd41955
First pass at Ryan's assertion code, minor tweaks to come.
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
233 } |
c5925cd41955
First pass at Ryan's assertion code, minor tweaks to come.
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
234 #endif |
c5925cd41955
First pass at Ryan's assertion code, minor tweaks to come.
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
235 } |
c5925cd41955
First pass at Ryan's assertion code, minor tweaks to come.
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
236 |
c5925cd41955
First pass at Ryan's assertion code, minor tweaks to come.
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
237 |
c5925cd41955
First pass at Ryan's assertion code, minor tweaks to come.
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
238 static void SDL_AbortAssertion(void) |
c5925cd41955
First pass at Ryan's assertion code, minor tweaks to come.
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
239 { |
c5925cd41955
First pass at Ryan's assertion code, minor tweaks to come.
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
240 SDL_Quit(); |
c5925cd41955
First pass at Ryan's assertion code, minor tweaks to come.
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
241 #ifdef _WINDOWS |
c5925cd41955
First pass at Ryan's assertion code, minor tweaks to come.
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
242 ExitProcess(42); |
c5925cd41955
First pass at Ryan's assertion code, minor tweaks to come.
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
243 #elif unix || __APPLE__ |
c5925cd41955
First pass at Ryan's assertion code, minor tweaks to come.
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
244 _exit(42); |
c5925cd41955
First pass at Ryan's assertion code, minor tweaks to come.
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
245 #else |
c5925cd41955
First pass at Ryan's assertion code, minor tweaks to come.
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
246 #error Please define your platform or set SDL_ASSERT_LEVEL to 0. |
c5925cd41955
First pass at Ryan's assertion code, minor tweaks to come.
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
247 #endif |
c5925cd41955
First pass at Ryan's assertion code, minor tweaks to come.
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
248 } |
c5925cd41955
First pass at Ryan's assertion code, minor tweaks to come.
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
249 |
c5925cd41955
First pass at Ryan's assertion code, minor tweaks to come.
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
250 |
c5925cd41955
First pass at Ryan's assertion code, minor tweaks to come.
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
251 static SDL_assert_state SDL_PromptAssertion(const SDL_assert_data *data) |
c5925cd41955
First pass at Ryan's assertion code, minor tweaks to come.
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
252 { |
c5925cd41955
First pass at Ryan's assertion code, minor tweaks to come.
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
253 const char *envr; |
c5925cd41955
First pass at Ryan's assertion code, minor tweaks to come.
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
254 |
c5925cd41955
First pass at Ryan's assertion code, minor tweaks to come.
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
255 debug_print("\n\n" |
c5925cd41955
First pass at Ryan's assertion code, minor tweaks to come.
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
256 "Assertion failure at %s (%s:%d), triggered %u time%s:\n" |
c5925cd41955
First pass at Ryan's assertion code, minor tweaks to come.
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
257 " '%s'\n" |
c5925cd41955
First pass at Ryan's assertion code, minor tweaks to come.
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
258 "\n", |
c5925cd41955
First pass at Ryan's assertion code, minor tweaks to come.
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
259 data->function, data->filename, data->linenum, |
c5925cd41955
First pass at Ryan's assertion code, minor tweaks to come.
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
260 data->trigger_count, (data->trigger_count == 1) ? "" : "s", |
c5925cd41955
First pass at Ryan's assertion code, minor tweaks to come.
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
261 data->condition); |
c5925cd41955
First pass at Ryan's assertion code, minor tweaks to come.
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
262 |
c5925cd41955
First pass at Ryan's assertion code, minor tweaks to come.
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
263 /* let env. variable override, so unit tests won't block in a GUI. */ |
c5925cd41955
First pass at Ryan's assertion code, minor tweaks to come.
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
264 envr = SDL_getenv("SDL_ASSERT"); |
c5925cd41955
First pass at Ryan's assertion code, minor tweaks to come.
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
265 if (envr != NULL) { |
c5925cd41955
First pass at Ryan's assertion code, minor tweaks to come.
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
266 if (SDL_strcmp(envr, "abort") == 0) { |
c5925cd41955
First pass at Ryan's assertion code, minor tweaks to come.
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
267 return SDL_ASSERTION_ABORT; |
c5925cd41955
First pass at Ryan's assertion code, minor tweaks to come.
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
268 } else if (SDL_strcmp(envr, "break") == 0) { |
c5925cd41955
First pass at Ryan's assertion code, minor tweaks to come.
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
269 return SDL_ASSERTION_BREAK; |
c5925cd41955
First pass at Ryan's assertion code, minor tweaks to come.
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
270 } else if (SDL_strcmp(envr, "retry") == 0) { |
c5925cd41955
First pass at Ryan's assertion code, minor tweaks to come.
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
271 return SDL_ASSERTION_RETRY; |
c5925cd41955
First pass at Ryan's assertion code, minor tweaks to come.
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
272 } else if (SDL_strcmp(envr, "ignore") == 0) { |
c5925cd41955
First pass at Ryan's assertion code, minor tweaks to come.
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
273 return SDL_ASSERTION_IGNORE; |
c5925cd41955
First pass at Ryan's assertion code, minor tweaks to come.
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
274 } else if (SDL_strcmp(envr, "always_ignore") == 0) { |
c5925cd41955
First pass at Ryan's assertion code, minor tweaks to come.
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
275 return SDL_ASSERTION_ALWAYS_IGNORE; |
c5925cd41955
First pass at Ryan's assertion code, minor tweaks to come.
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
276 } else { |
c5925cd41955
First pass at Ryan's assertion code, minor tweaks to come.
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
277 return SDL_ASSERTION_ABORT; /* oh well. */ |
c5925cd41955
First pass at Ryan's assertion code, minor tweaks to come.
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
278 } |
c5925cd41955
First pass at Ryan's assertion code, minor tweaks to come.
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
279 } |
c5925cd41955
First pass at Ryan's assertion code, minor tweaks to come.
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
280 |
c5925cd41955
First pass at Ryan's assertion code, minor tweaks to come.
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
281 /* platform-specific UI... */ |
c5925cd41955
First pass at Ryan's assertion code, minor tweaks to come.
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
282 |
c5925cd41955
First pass at Ryan's assertion code, minor tweaks to come.
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
283 #ifdef _WINDOWS |
c5925cd41955
First pass at Ryan's assertion code, minor tweaks to come.
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
284 return SDL_PromptAssertion_windows(data); |
c5925cd41955
First pass at Ryan's assertion code, minor tweaks to come.
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
285 |
c5925cd41955
First pass at Ryan's assertion code, minor tweaks to come.
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
286 #elif __APPLE__ |
c5925cd41955
First pass at Ryan's assertion code, minor tweaks to come.
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
287 /* This has to be done in an Objective-C (*.m) file, so we call out. */ |
c5925cd41955
First pass at Ryan's assertion code, minor tweaks to come.
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
288 extern SDL_assert_state SDL_PromptAssertion_cocoa(const SDL_assert_data *); |
c5925cd41955
First pass at Ryan's assertion code, minor tweaks to come.
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
289 return SDL_PromptAssertion_cocoa(data); |
c5925cd41955
First pass at Ryan's assertion code, minor tweaks to come.
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
290 |
c5925cd41955
First pass at Ryan's assertion code, minor tweaks to come.
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
291 #elif unix |
c5925cd41955
First pass at Ryan's assertion code, minor tweaks to come.
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
292 /* this is a little hacky. */ |
c5925cd41955
First pass at Ryan's assertion code, minor tweaks to come.
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
293 for ( ; ; ) { |
c5925cd41955
First pass at Ryan's assertion code, minor tweaks to come.
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
294 char buf[32]; |
c5925cd41955
First pass at Ryan's assertion code, minor tweaks to come.
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
295 fprintf(stderr, "Abort/Break/Retry/Ignore/AlwaysIgnore? [abriA] : "); |
c5925cd41955
First pass at Ryan's assertion code, minor tweaks to come.
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
296 fflush(stderr); |
c5925cd41955
First pass at Ryan's assertion code, minor tweaks to come.
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
297 if (fgets(buf, sizeof (buf), stdin) == NULL) { |
c5925cd41955
First pass at Ryan's assertion code, minor tweaks to come.
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
298 return SDL_ASSERTION_ABORT; |
c5925cd41955
First pass at Ryan's assertion code, minor tweaks to come.
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
299 } |
c5925cd41955
First pass at Ryan's assertion code, minor tweaks to come.
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
300 |
c5925cd41955
First pass at Ryan's assertion code, minor tweaks to come.
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
301 if (SDL_strcmp(buf, "a") == 0) { |
c5925cd41955
First pass at Ryan's assertion code, minor tweaks to come.
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
302 return SDL_ASSERTION_ABORT; |
c5925cd41955
First pass at Ryan's assertion code, minor tweaks to come.
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
303 } else if (SDL_strcmp(envr, "b") == 0) { |
c5925cd41955
First pass at Ryan's assertion code, minor tweaks to come.
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
304 return SDL_ASSERTION_BREAK; |
c5925cd41955
First pass at Ryan's assertion code, minor tweaks to come.
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
305 } else if (SDL_strcmp(envr, "r") == 0) { |
c5925cd41955
First pass at Ryan's assertion code, minor tweaks to come.
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
306 return SDL_ASSERTION_RETRY; |
c5925cd41955
First pass at Ryan's assertion code, minor tweaks to come.
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
307 } else if (SDL_strcmp(envr, "i") == 0) { |
c5925cd41955
First pass at Ryan's assertion code, minor tweaks to come.
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
308 return SDL_ASSERTION_IGNORE; |
c5925cd41955
First pass at Ryan's assertion code, minor tweaks to come.
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
309 } else if (SDL_strcmp(envr, "A") == 0) { |
c5925cd41955
First pass at Ryan's assertion code, minor tweaks to come.
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
310 return SDL_ASSERTION_ALWAYS_IGNORE; |
c5925cd41955
First pass at Ryan's assertion code, minor tweaks to come.
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
311 } |
c5925cd41955
First pass at Ryan's assertion code, minor tweaks to come.
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
312 } |
c5925cd41955
First pass at Ryan's assertion code, minor tweaks to come.
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
313 |
c5925cd41955
First pass at Ryan's assertion code, minor tweaks to come.
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
314 #else |
c5925cd41955
First pass at Ryan's assertion code, minor tweaks to come.
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
315 #error Please define your platform or set SDL_ASSERT_LEVEL to 0. |
c5925cd41955
First pass at Ryan's assertion code, minor tweaks to come.
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
316 #endif |
c5925cd41955
First pass at Ryan's assertion code, minor tweaks to come.
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
317 |
c5925cd41955
First pass at Ryan's assertion code, minor tweaks to come.
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
318 return SDL_ASSERTION_ABORT; |
c5925cd41955
First pass at Ryan's assertion code, minor tweaks to come.
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
319 } |
c5925cd41955
First pass at Ryan's assertion code, minor tweaks to come.
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
320 |
c5925cd41955
First pass at Ryan's assertion code, minor tweaks to come.
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
321 |
c5925cd41955
First pass at Ryan's assertion code, minor tweaks to come.
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
322 static SDL_mutex *assertion_mutex = NULL; |
c5925cd41955
First pass at Ryan's assertion code, minor tweaks to come.
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
323 |
c5925cd41955
First pass at Ryan's assertion code, minor tweaks to come.
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
324 SDL_assert_state |
c5925cd41955
First pass at Ryan's assertion code, minor tweaks to come.
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
325 SDL_ReportAssertion(SDL_assert_data *data, const char *func, int line) |
c5925cd41955
First pass at Ryan's assertion code, minor tweaks to come.
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
326 { |
c5925cd41955
First pass at Ryan's assertion code, minor tweaks to come.
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
327 SDL_assert_state state; |
c5925cd41955
First pass at Ryan's assertion code, minor tweaks to come.
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
328 |
c5925cd41955
First pass at Ryan's assertion code, minor tweaks to come.
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
329 if (SDL_LockMutex(assertion_mutex) < 0) { |
c5925cd41955
First pass at Ryan's assertion code, minor tweaks to come.
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
330 return SDL_ASSERTION_IGNORE; /* oh well, I guess. */ |
c5925cd41955
First pass at Ryan's assertion code, minor tweaks to come.
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
331 } |
c5925cd41955
First pass at Ryan's assertion code, minor tweaks to come.
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
332 |
c5925cd41955
First pass at Ryan's assertion code, minor tweaks to come.
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
333 /* doing this because Visual C is upset over assigning in the macro. */ |
c5925cd41955
First pass at Ryan's assertion code, minor tweaks to come.
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
334 if (data->trigger_count == 0) { |
c5925cd41955
First pass at Ryan's assertion code, minor tweaks to come.
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
335 data->function = func; |
c5925cd41955
First pass at Ryan's assertion code, minor tweaks to come.
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
336 data->linenum = line; |
c5925cd41955
First pass at Ryan's assertion code, minor tweaks to come.
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
337 } |
c5925cd41955
First pass at Ryan's assertion code, minor tweaks to come.
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
338 |
c5925cd41955
First pass at Ryan's assertion code, minor tweaks to come.
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
339 SDL_AddAssertionToReport(data); |
c5925cd41955
First pass at Ryan's assertion code, minor tweaks to come.
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
340 |
c5925cd41955
First pass at Ryan's assertion code, minor tweaks to come.
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
341 data->trigger_count++; |
c5925cd41955
First pass at Ryan's assertion code, minor tweaks to come.
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
342 if (data->always_ignore) { |
c5925cd41955
First pass at Ryan's assertion code, minor tweaks to come.
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
343 SDL_UnlockMutex(assertion_mutex); |
c5925cd41955
First pass at Ryan's assertion code, minor tweaks to come.
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
344 return SDL_ASSERTION_IGNORE; |
c5925cd41955
First pass at Ryan's assertion code, minor tweaks to come.
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
345 } |
c5925cd41955
First pass at Ryan's assertion code, minor tweaks to come.
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
346 |
c5925cd41955
First pass at Ryan's assertion code, minor tweaks to come.
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
347 state = SDL_PromptAssertion(data); |
c5925cd41955
First pass at Ryan's assertion code, minor tweaks to come.
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
348 |
c5925cd41955
First pass at Ryan's assertion code, minor tweaks to come.
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
349 switch (state) |
c5925cd41955
First pass at Ryan's assertion code, minor tweaks to come.
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
350 { |
c5925cd41955
First pass at Ryan's assertion code, minor tweaks to come.
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
351 case SDL_ASSERTION_ABORT: |
c5925cd41955
First pass at Ryan's assertion code, minor tweaks to come.
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
352 SDL_UnlockMutex(assertion_mutex); /* in case we assert in quit. */ |
c5925cd41955
First pass at Ryan's assertion code, minor tweaks to come.
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
353 SDL_AbortAssertion(); |
c5925cd41955
First pass at Ryan's assertion code, minor tweaks to come.
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
354 return SDL_ASSERTION_IGNORE; /* shouldn't return, but oh well. */ |
c5925cd41955
First pass at Ryan's assertion code, minor tweaks to come.
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
355 |
c5925cd41955
First pass at Ryan's assertion code, minor tweaks to come.
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
356 case SDL_ASSERTION_ALWAYS_IGNORE: |
c5925cd41955
First pass at Ryan's assertion code, minor tweaks to come.
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
357 state = SDL_ASSERTION_IGNORE; |
c5925cd41955
First pass at Ryan's assertion code, minor tweaks to come.
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
358 data->always_ignore = 1; |
c5925cd41955
First pass at Ryan's assertion code, minor tweaks to come.
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
359 break; |
c5925cd41955
First pass at Ryan's assertion code, minor tweaks to come.
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
360 |
c5925cd41955
First pass at Ryan's assertion code, minor tweaks to come.
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
361 case SDL_ASSERTION_IGNORE: |
c5925cd41955
First pass at Ryan's assertion code, minor tweaks to come.
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
362 case SDL_ASSERTION_RETRY: |
c5925cd41955
First pass at Ryan's assertion code, minor tweaks to come.
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
363 case SDL_ASSERTION_BREAK: |
c5925cd41955
First pass at Ryan's assertion code, minor tweaks to come.
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
364 break; /* macro handles these. */ |
c5925cd41955
First pass at Ryan's assertion code, minor tweaks to come.
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
365 } |
c5925cd41955
First pass at Ryan's assertion code, minor tweaks to come.
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
366 |
c5925cd41955
First pass at Ryan's assertion code, minor tweaks to come.
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
367 SDL_UnlockMutex(assertion_mutex); |
c5925cd41955
First pass at Ryan's assertion code, minor tweaks to come.
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
368 |
c5925cd41955
First pass at Ryan's assertion code, minor tweaks to come.
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
369 return state; |
c5925cd41955
First pass at Ryan's assertion code, minor tweaks to come.
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
370 } |
c5925cd41955
First pass at Ryan's assertion code, minor tweaks to come.
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
371 |
c5925cd41955
First pass at Ryan's assertion code, minor tweaks to come.
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
372 #endif /* SDL_ASSERT_LEVEL > 0 */ |
c5925cd41955
First pass at Ryan's assertion code, minor tweaks to come.
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
373 |
c5925cd41955
First pass at Ryan's assertion code, minor tweaks to come.
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
374 |
c5925cd41955
First pass at Ryan's assertion code, minor tweaks to come.
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
375 int SDL_AssertionsInit(void) |
c5925cd41955
First pass at Ryan's assertion code, minor tweaks to come.
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
376 { |
c5925cd41955
First pass at Ryan's assertion code, minor tweaks to come.
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
377 #if (SDL_ASSERT_LEVEL > 0) |
c5925cd41955
First pass at Ryan's assertion code, minor tweaks to come.
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
378 assertion_mutex = SDL_CreateMutex(); |
c5925cd41955
First pass at Ryan's assertion code, minor tweaks to come.
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
379 if (assertion_mutex == NULL) { |
c5925cd41955
First pass at Ryan's assertion code, minor tweaks to come.
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
380 return -1; |
c5925cd41955
First pass at Ryan's assertion code, minor tweaks to come.
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
381 } |
c5925cd41955
First pass at Ryan's assertion code, minor tweaks to come.
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
382 #endif |
c5925cd41955
First pass at Ryan's assertion code, minor tweaks to come.
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
383 return 0; |
c5925cd41955
First pass at Ryan's assertion code, minor tweaks to come.
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
384 } |
c5925cd41955
First pass at Ryan's assertion code, minor tweaks to come.
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
385 |
c5925cd41955
First pass at Ryan's assertion code, minor tweaks to come.
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
386 void SDL_AssertionsQuit(void) |
c5925cd41955
First pass at Ryan's assertion code, minor tweaks to come.
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
387 { |
c5925cd41955
First pass at Ryan's assertion code, minor tweaks to come.
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
388 #if (SDL_ASSERT_LEVEL > 0) |
c5925cd41955
First pass at Ryan's assertion code, minor tweaks to come.
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
389 SDL_GenerateAssertionReport(); |
c5925cd41955
First pass at Ryan's assertion code, minor tweaks to come.
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
390 SDL_DestroyMutex(assertion_mutex); |
c5925cd41955
First pass at Ryan's assertion code, minor tweaks to come.
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
391 assertion_mutex = NULL; |
c5925cd41955
First pass at Ryan's assertion code, minor tweaks to come.
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
392 #endif |
c5925cd41955
First pass at Ryan's assertion code, minor tweaks to come.
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
393 } |
c5925cd41955
First pass at Ryan's assertion code, minor tweaks to come.
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
394 |
c5925cd41955
First pass at Ryan's assertion code, minor tweaks to come.
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
395 /* vi: set ts=4 sw=4 expandtab: */ |
c5925cd41955
First pass at Ryan's assertion code, minor tweaks to come.
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
396 |