Mercurial > sdl-ios-xcode
annotate src/SDL_assert.c @ 3662:6a0b3048f271
Handle assertion failures when SDL_Init() isn't called.
author | Ryan C. Gordon <icculus@icculus.org> |
---|---|
date | Wed, 13 Jan 2010 09:44:17 +0000 |
parents | 22b6a0c7ea6e |
children | 8bdc37b1a52a |
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 |
3651 | 23 #include "SDL.h" |
3647
c5925cd41955
First pass at Ryan's assertion code, minor tweaks to come.
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
24 #include "SDL_assert.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> |
3648
a9d830c05998
Fixed build problems with gcc __attribute__.
Ryan C. Gordon <icculus@icculus.org>
parents:
3647
diff
changeset
|
34 #include <unistd.h> |
3647
c5925cd41955
First pass at Ryan's assertion code, minor tweaks to come.
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
35 #endif |
c5925cd41955
First pass at Ryan's assertion code, minor tweaks to come.
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
36 |
c5925cd41955
First pass at Ryan's assertion code, minor tweaks to come.
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
37 /* 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
|
38 * generate a report later. |
c5925cd41955
First pass at Ryan's assertion code, minor tweaks to come.
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
39 */ |
c5925cd41955
First pass at Ryan's assertion code, minor tweaks to come.
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
40 #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
|
41 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
|
42 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
|
43 #endif |
c5925cd41955
First pass at Ryan's assertion code, minor tweaks to come.
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
44 |
3648
a9d830c05998
Fixed build problems with gcc __attribute__.
Ryan C. Gordon <icculus@icculus.org>
parents:
3647
diff
changeset
|
45 #ifdef __GNUC__ |
3661
22b6a0c7ea6e
Handle assertion failures during assertion handler.
Ryan C. Gordon <icculus@icculus.org>
parents:
3657
diff
changeset
|
46 static void |
22b6a0c7ea6e
Handle assertion failures during assertion handler.
Ryan C. Gordon <icculus@icculus.org>
parents:
3657
diff
changeset
|
47 debug_print(const char *fmt, ...) __attribute__((format (printf, 1, 2))); |
3648
a9d830c05998
Fixed build problems with gcc __attribute__.
Ryan C. Gordon <icculus@icculus.org>
parents:
3647
diff
changeset
|
48 #endif |
a9d830c05998
Fixed build problems with gcc __attribute__.
Ryan C. Gordon <icculus@icculus.org>
parents:
3647
diff
changeset
|
49 |
a9d830c05998
Fixed build problems with gcc __attribute__.
Ryan C. Gordon <icculus@icculus.org>
parents:
3647
diff
changeset
|
50 static void |
a9d830c05998
Fixed build problems with gcc __attribute__.
Ryan C. Gordon <icculus@icculus.org>
parents:
3647
diff
changeset
|
51 debug_print(const char *fmt, ...) |
3647
c5925cd41955
First pass at Ryan's assertion code, minor tweaks to come.
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
52 { |
c5925cd41955
First pass at Ryan's assertion code, minor tweaks to come.
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
53 #ifdef _WINDOWS |
c5925cd41955
First pass at Ryan's assertion code, minor tweaks to come.
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
54 /* 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
|
55 char buf[1024]; |
c5925cd41955
First pass at Ryan's assertion code, minor tweaks to come.
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
56 char *startptr; |
c5925cd41955
First pass at Ryan's assertion code, minor tweaks to come.
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
57 char *ptr; |
c5925cd41955
First pass at Ryan's assertion code, minor tweaks to come.
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
58 int len; |
c5925cd41955
First pass at Ryan's assertion code, minor tweaks to come.
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
59 va_list ap; |
c5925cd41955
First pass at Ryan's assertion code, minor tweaks to come.
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
60 va_start(ap, fmt); |
c5925cd41955
First pass at Ryan's assertion code, minor tweaks to come.
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
61 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
|
62 va_end(ap); |
c5925cd41955
First pass at Ryan's assertion code, minor tweaks to come.
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
63 |
c5925cd41955
First pass at Ryan's assertion code, minor tweaks to come.
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
64 /* 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
|
65 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
|
66 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
|
67 } |
c5925cd41955
First pass at Ryan's assertion code, minor tweaks to come.
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
68 |
c5925cd41955
First pass at Ryan's assertion code, minor tweaks to come.
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
69 /* 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
|
70 startptr = buf; |
c5925cd41955
First pass at Ryan's assertion code, minor tweaks to come.
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
71 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
|
72 if (*ptr == '\n') { |
c5925cd41955
First pass at Ryan's assertion code, minor tweaks to come.
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
73 *ptr = '\0'; |
c5925cd41955
First pass at Ryan's assertion code, minor tweaks to come.
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
74 OutputDebugStringA(startptr); |
c5925cd41955
First pass at Ryan's assertion code, minor tweaks to come.
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
75 OutputDebugStringA("\r\n"); |
c5925cd41955
First pass at Ryan's assertion code, minor tweaks to come.
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
76 startptr = ptr+1; |
c5925cd41955
First pass at Ryan's assertion code, minor tweaks to come.
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
77 } |
c5925cd41955
First pass at Ryan's assertion code, minor tweaks to come.
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
78 } |
c5925cd41955
First pass at Ryan's assertion code, minor tweaks to come.
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
79 |
c5925cd41955
First pass at Ryan's assertion code, minor tweaks to come.
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
80 /* 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
|
81 if (startptr != ptr) { |
c5925cd41955
First pass at Ryan's assertion code, minor tweaks to come.
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
82 OutputDebugStringA(startptr); |
c5925cd41955
First pass at Ryan's assertion code, minor tweaks to come.
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
83 } |
c5925cd41955
First pass at Ryan's assertion code, minor tweaks to come.
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
84 #else |
c5925cd41955
First pass at Ryan's assertion code, minor tweaks to come.
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
85 /* 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
|
86 va_list ap; |
c5925cd41955
First pass at Ryan's assertion code, minor tweaks to come.
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
87 va_start(ap, fmt); |
c5925cd41955
First pass at Ryan's assertion code, minor tweaks to come.
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
88 fprintf(stderr, fmt, ap); |
c5925cd41955
First pass at Ryan's assertion code, minor tweaks to come.
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
89 va_end(ap); |
c5925cd41955
First pass at Ryan's assertion code, minor tweaks to come.
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
90 fflush(stderr); |
c5925cd41955
First pass at Ryan's assertion code, minor tweaks to come.
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
91 #endif |
c5925cd41955
First pass at Ryan's assertion code, minor tweaks to come.
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
92 } |
c5925cd41955
First pass at Ryan's assertion code, minor tweaks to come.
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
93 |
c5925cd41955
First pass at Ryan's assertion code, minor tweaks to come.
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
94 |
c5925cd41955
First pass at Ryan's assertion code, minor tweaks to come.
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
95 #ifdef _WINDOWS |
c5925cd41955
First pass at Ryan's assertion code, minor tweaks to come.
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
96 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
|
97 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
|
98 |
c5925cd41955
First pass at Ryan's assertion code, minor tweaks to come.
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
99 static LRESULT CALLBACK |
c5925cd41955
First pass at Ryan's assertion code, minor tweaks to come.
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
100 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
|
101 { |
c5925cd41955
First pass at Ryan's assertion code, minor tweaks to come.
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
102 switch (msg) |
c5925cd41955
First pass at Ryan's assertion code, minor tweaks to come.
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
103 { |
c5925cd41955
First pass at Ryan's assertion code, minor tweaks to come.
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
104 case WM_CREATE: |
c5925cd41955
First pass at Ryan's assertion code, minor tweaks to come.
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
105 { |
c5925cd41955
First pass at Ryan's assertion code, minor tweaks to come.
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
106 /* !!! 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
|
107 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
|
108 char buf[1024]; |
c5925cd41955
First pass at Ryan's assertion code, minor tweaks to come.
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
109 const int w = 100; |
c5925cd41955
First pass at Ryan's assertion code, minor tweaks to come.
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
110 const int h = 25; |
c5925cd41955
First pass at Ryan's assertion code, minor tweaks to come.
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
111 const int gap = 10; |
c5925cd41955
First pass at Ryan's assertion code, minor tweaks to come.
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
112 int x = gap; |
c5925cd41955
First pass at Ryan's assertion code, minor tweaks to come.
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
113 int y = 50; |
c5925cd41955
First pass at Ryan's assertion code, minor tweaks to come.
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
114 int len; |
c5925cd41955
First pass at Ryan's assertion code, minor tweaks to come.
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
115 int i; |
c5925cd41955
First pass at Ryan's assertion code, minor tweaks to come.
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
116 static const struct { |
c5925cd41955
First pass at Ryan's assertion code, minor tweaks to come.
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
117 const char *name; |
c5925cd41955
First pass at Ryan's assertion code, minor tweaks to come.
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
118 SDL_assert_state state; |
c5925cd41955
First pass at Ryan's assertion code, minor tweaks to come.
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
119 } buttons[] = { |
c5925cd41955
First pass at Ryan's assertion code, minor tweaks to come.
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
120 {"Abort", SDL_ASSERTION_ABORT }, |
c5925cd41955
First pass at Ryan's assertion code, minor tweaks to come.
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
121 {"Break", SDL_ASSERTION_BREAK }, |
c5925cd41955
First pass at Ryan's assertion code, minor tweaks to come.
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
122 {"Retry", SDL_ASSERTION_RETRY }, |
c5925cd41955
First pass at Ryan's assertion code, minor tweaks to come.
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
123 {"Ignore", SDL_ASSERTION_IGNORE }, |
c5925cd41955
First pass at Ryan's assertion code, minor tweaks to come.
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
124 {"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
|
125 }; |
c5925cd41955
First pass at Ryan's assertion code, minor tweaks to come.
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
126 |
c5925cd41955
First pass at Ryan's assertion code, minor tweaks to come.
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
127 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
|
128 "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
|
129 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
|
130 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
|
131 data->condition); |
c5925cd41955
First pass at Ryan's assertion code, minor tweaks to come.
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
132 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
|
133 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
|
134 } |
c5925cd41955
First pass at Ryan's assertion code, minor tweaks to come.
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
135 |
c5925cd41955
First pass at Ryan's assertion code, minor tweaks to come.
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
136 CreateWindowA("STATIC", buf, |
c5925cd41955
First pass at Ryan's assertion code, minor tweaks to come.
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
137 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
|
138 x, y, 550, 100, |
c5925cd41955
First pass at Ryan's assertion code, minor tweaks to come.
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
139 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
|
140 y += 110; |
c5925cd41955
First pass at Ryan's assertion code, minor tweaks to come.
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
141 |
c5925cd41955
First pass at Ryan's assertion code, minor tweaks to come.
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
142 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
|
143 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
|
144 WS_VISIBLE | WS_CHILD, |
c5925cd41955
First pass at Ryan's assertion code, minor tweaks to come.
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
145 x, y, w, h, |
c5925cd41955
First pass at Ryan's assertion code, minor tweaks to come.
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
146 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
|
147 x += w + gap; |
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 break; |
c5925cd41955
First pass at Ryan's assertion code, minor tweaks to come.
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
150 } |
c5925cd41955
First pass at Ryan's assertion code, minor tweaks to come.
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
151 |
c5925cd41955
First pass at Ryan's assertion code, minor tweaks to come.
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
152 case WM_COMMAND: |
c5925cd41955
First pass at Ryan's assertion code, minor tweaks to come.
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
153 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
|
154 SDL_Windows_AssertData = NULL; |
c5925cd41955
First pass at Ryan's assertion code, minor tweaks to come.
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
155 break; |
c5925cd41955
First pass at Ryan's assertion code, minor tweaks to come.
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
156 |
c5925cd41955
First pass at Ryan's assertion code, minor tweaks to come.
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
157 case WM_DESTROY: |
c5925cd41955
First pass at Ryan's assertion code, minor tweaks to come.
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
158 SDL_Windows_AssertData = NULL; |
c5925cd41955
First pass at Ryan's assertion code, minor tweaks to come.
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
159 break; |
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 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
|
163 } |
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 static SDL_assert_state |
c5925cd41955
First pass at Ryan's assertion code, minor tweaks to come.
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
166 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
|
167 { |
c5925cd41955
First pass at Ryan's assertion code, minor tweaks to come.
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
168 HINSTANCE hInstance = 0; /* !!! FIXME? */ |
c5925cd41955
First pass at Ryan's assertion code, minor tweaks to come.
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
169 HWND hwnd; |
c5925cd41955
First pass at Ryan's assertion code, minor tweaks to come.
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
170 MSG msg; |
c5925cd41955
First pass at Ryan's assertion code, minor tweaks to come.
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
171 WNDCLASS wc = {0}; |
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 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
|
174 SDL_Windows_AssertData = data; |
c5925cd41955
First pass at Ryan's assertion code, minor tweaks to come.
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
175 |
c5925cd41955
First pass at Ryan's assertion code, minor tweaks to come.
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
176 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
|
177 wc.hInstance = hInstance ; |
c5925cd41955
First pass at Ryan's assertion code, minor tweaks to come.
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
178 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
|
179 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
|
180 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
|
181 |
c5925cd41955
First pass at Ryan's assertion code, minor tweaks to come.
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
182 RegisterClass(&wc); |
c5925cd41955
First pass at Ryan's assertion code, minor tweaks to come.
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
183 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
|
184 WS_OVERLAPPEDWINDOW | WS_VISIBLE, |
c5925cd41955
First pass at Ryan's assertion code, minor tweaks to come.
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
185 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
|
186 |
c5925cd41955
First pass at Ryan's assertion code, minor tweaks to come.
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
187 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
|
188 TranslateMessage(&msg); |
c5925cd41955
First pass at Ryan's assertion code, minor tweaks to come.
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
189 DispatchMessage(&msg); |
c5925cd41955
First pass at Ryan's assertion code, minor tweaks to come.
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
190 } |
c5925cd41955
First pass at Ryan's assertion code, minor tweaks to come.
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
191 |
c5925cd41955
First pass at Ryan's assertion code, minor tweaks to come.
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
192 DestroyWindow(hwnd); |
c5925cd41955
First pass at Ryan's assertion code, minor tweaks to come.
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
193 UnregisterClass(wc.lpszClassName, hInstance); |
c5925cd41955
First pass at Ryan's assertion code, minor tweaks to come.
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
194 return SDL_Windows_AssertChoice; |
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 #endif |
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 |
c5925cd41955
First pass at Ryan's assertion code, minor tweaks to come.
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
199 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
|
200 { |
c5925cd41955
First pass at Ryan's assertion code, minor tweaks to come.
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
201 #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
|
202 /* (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
|
203 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
|
204 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
|
205 data->next = triggered_assertions; |
c5925cd41955
First pass at Ryan's assertion code, minor tweaks to come.
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
206 triggered_assertions = data; |
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 #endif |
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 |
c5925cd41955
First pass at Ryan's assertion code, minor tweaks to come.
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
211 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
|
212 { |
c5925cd41955
First pass at Ryan's assertion code, minor tweaks to come.
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
213 #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
|
214 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
|
215 { |
c5925cd41955
First pass at Ryan's assertion code, minor tweaks to come.
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
216 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
|
217 |
c5925cd41955
First pass at Ryan's assertion code, minor tweaks to come.
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
218 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
|
219 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
|
220 |
c5925cd41955
First pass at Ryan's assertion code, minor tweaks to come.
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
221 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
|
222 debug_print( |
c5925cd41955
First pass at Ryan's assertion code, minor tweaks to come.
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
223 "'%s'\n" |
c5925cd41955
First pass at Ryan's assertion code, minor tweaks to come.
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
224 " * %s (%s:%d)\n" |
c5925cd41955
First pass at Ryan's assertion code, minor tweaks to come.
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
225 " * 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
|
226 " * always ignore: %s.\n", |
c5925cd41955
First pass at Ryan's assertion code, minor tweaks to come.
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
227 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
|
228 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
|
229 (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
|
230 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
|
231 item = item->next; |
c5925cd41955
First pass at Ryan's assertion code, minor tweaks to come.
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
232 } |
c5925cd41955
First pass at Ryan's assertion code, minor tweaks to come.
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
233 debug_print("\n"); |
c5925cd41955
First pass at Ryan's assertion code, minor tweaks to come.
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
234 |
c5925cd41955
First pass at Ryan's assertion code, minor tweaks to come.
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
235 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
|
236 } |
c5925cd41955
First pass at Ryan's assertion code, minor tweaks to come.
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
237 #endif |
c5925cd41955
First pass at Ryan's assertion code, minor tweaks to come.
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
238 } |
c5925cd41955
First pass at Ryan's assertion code, minor tweaks to come.
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
239 |
3661
22b6a0c7ea6e
Handle assertion failures during assertion handler.
Ryan C. Gordon <icculus@icculus.org>
parents:
3657
diff
changeset
|
240 static void SDL_ExitProcess(int exitcode) |
3647
c5925cd41955
First pass at Ryan's assertion code, minor tweaks to come.
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
241 { |
c5925cd41955
First pass at Ryan's assertion code, minor tweaks to come.
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
242 #ifdef _WINDOWS |
c5925cd41955
First pass at Ryan's assertion code, minor tweaks to come.
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
243 ExitProcess(42); |
3656
f17ea6f49745
Assume _exit() is available. It may be, even if unix isn't defined.
Sam Lantinga <slouken@libsdl.org>
parents:
3655
diff
changeset
|
244 #else |
3647
c5925cd41955
First pass at Ryan's assertion code, minor tweaks to come.
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
245 _exit(42); |
c5925cd41955
First pass at Ryan's assertion code, minor tweaks to come.
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
246 #endif |
c5925cd41955
First pass at Ryan's assertion code, minor tweaks to come.
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
247 } |
3661
22b6a0c7ea6e
Handle assertion failures during assertion handler.
Ryan C. Gordon <icculus@icculus.org>
parents:
3657
diff
changeset
|
248 |
22b6a0c7ea6e
Handle assertion failures during assertion handler.
Ryan C. Gordon <icculus@icculus.org>
parents:
3657
diff
changeset
|
249 static void SDL_AbortAssertion(void) |
22b6a0c7ea6e
Handle assertion failures during assertion handler.
Ryan C. Gordon <icculus@icculus.org>
parents:
3657
diff
changeset
|
250 { |
22b6a0c7ea6e
Handle assertion failures during assertion handler.
Ryan C. Gordon <icculus@icculus.org>
parents:
3657
diff
changeset
|
251 SDL_Quit(); |
22b6a0c7ea6e
Handle assertion failures during assertion handler.
Ryan C. Gordon <icculus@icculus.org>
parents:
3657
diff
changeset
|
252 SDL_ExitProcess(42); |
22b6a0c7ea6e
Handle assertion failures during assertion handler.
Ryan C. Gordon <icculus@icculus.org>
parents:
3657
diff
changeset
|
253 } |
22b6a0c7ea6e
Handle assertion failures during assertion handler.
Ryan C. Gordon <icculus@icculus.org>
parents:
3657
diff
changeset
|
254 |
3647
c5925cd41955
First pass at Ryan's assertion code, minor tweaks to come.
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
255 |
c5925cd41955
First pass at Ryan's assertion code, minor tweaks to come.
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
256 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
|
257 { |
c5925cd41955
First pass at Ryan's assertion code, minor tweaks to come.
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
258 const char *envr; |
3657
eaea59cee6f2
Leave fullscreen mode to pop an assertion dialog
Sam Lantinga <slouken@libsdl.org>
parents:
3656
diff
changeset
|
259 SDL_assert_state state = SDL_ASSERTION_ABORT; |
eaea59cee6f2
Leave fullscreen mode to pop an assertion dialog
Sam Lantinga <slouken@libsdl.org>
parents:
3656
diff
changeset
|
260 SDL_WindowID window; |
3647
c5925cd41955
First pass at Ryan's assertion code, minor tweaks to come.
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
261 |
c5925cd41955
First pass at Ryan's assertion code, minor tweaks to come.
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
262 debug_print("\n\n" |
c5925cd41955
First pass at Ryan's assertion code, minor tweaks to come.
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
263 "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
|
264 " '%s'\n" |
c5925cd41955
First pass at Ryan's assertion code, minor tweaks to come.
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
265 "\n", |
c5925cd41955
First pass at Ryan's assertion code, minor tweaks to come.
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
266 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
|
267 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
|
268 data->condition); |
c5925cd41955
First pass at Ryan's assertion code, minor tweaks to come.
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
269 |
3655
1cc7f0143c12
Moved SDL_FUNCTION out so it's always available, and added SDL_FILE and SDL_LINE
Sam Lantinga <slouken@libsdl.org>
parents:
3651
diff
changeset
|
270 /* let env. variable override, so unit tests won't block in a GUI. */ |
3647
c5925cd41955
First pass at Ryan's assertion code, minor tweaks to come.
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
271 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
|
272 if (envr != NULL) { |
c5925cd41955
First pass at Ryan's assertion code, minor tweaks to come.
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
273 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
|
274 return SDL_ASSERTION_ABORT; |
c5925cd41955
First pass at Ryan's assertion code, minor tweaks to come.
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
275 } 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
|
276 return SDL_ASSERTION_BREAK; |
c5925cd41955
First pass at Ryan's assertion code, minor tweaks to come.
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
277 } 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
|
278 return SDL_ASSERTION_RETRY; |
c5925cd41955
First pass at Ryan's assertion code, minor tweaks to come.
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
279 } 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
|
280 return SDL_ASSERTION_IGNORE; |
c5925cd41955
First pass at Ryan's assertion code, minor tweaks to come.
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
281 } 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
|
282 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
|
283 } else { |
c5925cd41955
First pass at Ryan's assertion code, minor tweaks to come.
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
284 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
|
285 } |
c5925cd41955
First pass at Ryan's assertion code, minor tweaks to come.
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
286 } |
c5925cd41955
First pass at Ryan's assertion code, minor tweaks to come.
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
287 |
3657
eaea59cee6f2
Leave fullscreen mode to pop an assertion dialog
Sam Lantinga <slouken@libsdl.org>
parents:
3656
diff
changeset
|
288 /* Leave fullscreen mode, if possible (scary!) */ |
eaea59cee6f2
Leave fullscreen mode to pop an assertion dialog
Sam Lantinga <slouken@libsdl.org>
parents:
3656
diff
changeset
|
289 window = SDL_GetFocusWindow(); |
eaea59cee6f2
Leave fullscreen mode to pop an assertion dialog
Sam Lantinga <slouken@libsdl.org>
parents:
3656
diff
changeset
|
290 if (window) { |
eaea59cee6f2
Leave fullscreen mode to pop an assertion dialog
Sam Lantinga <slouken@libsdl.org>
parents:
3656
diff
changeset
|
291 if (SDL_GetWindowFlags(window) & SDL_WINDOW_FULLSCREEN) { |
eaea59cee6f2
Leave fullscreen mode to pop an assertion dialog
Sam Lantinga <slouken@libsdl.org>
parents:
3656
diff
changeset
|
292 SDL_MinimizeWindow(window); |
eaea59cee6f2
Leave fullscreen mode to pop an assertion dialog
Sam Lantinga <slouken@libsdl.org>
parents:
3656
diff
changeset
|
293 } else { |
eaea59cee6f2
Leave fullscreen mode to pop an assertion dialog
Sam Lantinga <slouken@libsdl.org>
parents:
3656
diff
changeset
|
294 /* No need to mess with the window */ |
eaea59cee6f2
Leave fullscreen mode to pop an assertion dialog
Sam Lantinga <slouken@libsdl.org>
parents:
3656
diff
changeset
|
295 window = 0; |
eaea59cee6f2
Leave fullscreen mode to pop an assertion dialog
Sam Lantinga <slouken@libsdl.org>
parents:
3656
diff
changeset
|
296 } |
eaea59cee6f2
Leave fullscreen mode to pop an assertion dialog
Sam Lantinga <slouken@libsdl.org>
parents:
3656
diff
changeset
|
297 } |
eaea59cee6f2
Leave fullscreen mode to pop an assertion dialog
Sam Lantinga <slouken@libsdl.org>
parents:
3656
diff
changeset
|
298 |
3647
c5925cd41955
First pass at Ryan's assertion code, minor tweaks to come.
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
299 /* platform-specific UI... */ |
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 #ifdef _WINDOWS |
3657
eaea59cee6f2
Leave fullscreen mode to pop an assertion dialog
Sam Lantinga <slouken@libsdl.org>
parents:
3656
diff
changeset
|
302 state = SDL_PromptAssertion_windows(data); |
3647
c5925cd41955
First pass at Ryan's assertion code, minor tweaks to come.
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
303 |
c5925cd41955
First pass at Ryan's assertion code, minor tweaks to come.
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
304 #elif __APPLE__ |
c5925cd41955
First pass at Ryan's assertion code, minor tweaks to come.
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
305 /* 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
|
306 extern SDL_assert_state SDL_PromptAssertion_cocoa(const SDL_assert_data *); |
3657
eaea59cee6f2
Leave fullscreen mode to pop an assertion dialog
Sam Lantinga <slouken@libsdl.org>
parents:
3656
diff
changeset
|
307 state = SDL_PromptAssertion_cocoa(data); |
3647
c5925cd41955
First pass at Ryan's assertion code, minor tweaks to come.
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
308 |
3657
eaea59cee6f2
Leave fullscreen mode to pop an assertion dialog
Sam Lantinga <slouken@libsdl.org>
parents:
3656
diff
changeset
|
309 #else |
3647
c5925cd41955
First pass at Ryan's assertion code, minor tweaks to come.
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
310 /* 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
|
311 for ( ; ; ) { |
c5925cd41955
First pass at Ryan's assertion code, minor tweaks to come.
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
312 char buf[32]; |
c5925cd41955
First pass at Ryan's assertion code, minor tweaks to come.
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
313 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
|
314 fflush(stderr); |
c5925cd41955
First pass at Ryan's assertion code, minor tweaks to come.
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
315 if (fgets(buf, sizeof (buf), stdin) == NULL) { |
3657
eaea59cee6f2
Leave fullscreen mode to pop an assertion dialog
Sam Lantinga <slouken@libsdl.org>
parents:
3656
diff
changeset
|
316 break; |
3647
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 |
c5925cd41955
First pass at Ryan's assertion code, minor tweaks to come.
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
319 if (SDL_strcmp(buf, "a") == 0) { |
3657
eaea59cee6f2
Leave fullscreen mode to pop an assertion dialog
Sam Lantinga <slouken@libsdl.org>
parents:
3656
diff
changeset
|
320 state = SDL_ASSERTION_ABORT; |
eaea59cee6f2
Leave fullscreen mode to pop an assertion dialog
Sam Lantinga <slouken@libsdl.org>
parents:
3656
diff
changeset
|
321 break; |
3647
c5925cd41955
First pass at Ryan's assertion code, minor tweaks to come.
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
322 } else if (SDL_strcmp(envr, "b") == 0) { |
3657
eaea59cee6f2
Leave fullscreen mode to pop an assertion dialog
Sam Lantinga <slouken@libsdl.org>
parents:
3656
diff
changeset
|
323 state = SDL_ASSERTION_BREAK; |
eaea59cee6f2
Leave fullscreen mode to pop an assertion dialog
Sam Lantinga <slouken@libsdl.org>
parents:
3656
diff
changeset
|
324 break; |
3647
c5925cd41955
First pass at Ryan's assertion code, minor tweaks to come.
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
325 } else if (SDL_strcmp(envr, "r") == 0) { |
3657
eaea59cee6f2
Leave fullscreen mode to pop an assertion dialog
Sam Lantinga <slouken@libsdl.org>
parents:
3656
diff
changeset
|
326 state = SDL_ASSERTION_RETRY; |
eaea59cee6f2
Leave fullscreen mode to pop an assertion dialog
Sam Lantinga <slouken@libsdl.org>
parents:
3656
diff
changeset
|
327 break; |
3647
c5925cd41955
First pass at Ryan's assertion code, minor tweaks to come.
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
328 } else if (SDL_strcmp(envr, "i") == 0) { |
3657
eaea59cee6f2
Leave fullscreen mode to pop an assertion dialog
Sam Lantinga <slouken@libsdl.org>
parents:
3656
diff
changeset
|
329 state = SDL_ASSERTION_IGNORE; |
eaea59cee6f2
Leave fullscreen mode to pop an assertion dialog
Sam Lantinga <slouken@libsdl.org>
parents:
3656
diff
changeset
|
330 break; |
3647
c5925cd41955
First pass at Ryan's assertion code, minor tweaks to come.
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
331 } else if (SDL_strcmp(envr, "A") == 0) { |
3657
eaea59cee6f2
Leave fullscreen mode to pop an assertion dialog
Sam Lantinga <slouken@libsdl.org>
parents:
3656
diff
changeset
|
332 state = SDL_ASSERTION_ALWAYS_IGNORE; |
eaea59cee6f2
Leave fullscreen mode to pop an assertion dialog
Sam Lantinga <slouken@libsdl.org>
parents:
3656
diff
changeset
|
333 break; |
3647
c5925cd41955
First pass at Ryan's assertion code, minor tweaks to come.
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
334 } |
c5925cd41955
First pass at Ryan's assertion code, minor tweaks to come.
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
335 } |
c5925cd41955
First pass at Ryan's assertion code, minor tweaks to come.
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
336 #endif |
c5925cd41955
First pass at Ryan's assertion code, minor tweaks to come.
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
337 |
3657
eaea59cee6f2
Leave fullscreen mode to pop an assertion dialog
Sam Lantinga <slouken@libsdl.org>
parents:
3656
diff
changeset
|
338 /* Re-enter fullscreen mode */ |
eaea59cee6f2
Leave fullscreen mode to pop an assertion dialog
Sam Lantinga <slouken@libsdl.org>
parents:
3656
diff
changeset
|
339 if (window) { |
eaea59cee6f2
Leave fullscreen mode to pop an assertion dialog
Sam Lantinga <slouken@libsdl.org>
parents:
3656
diff
changeset
|
340 SDL_RestoreWindow(window); |
eaea59cee6f2
Leave fullscreen mode to pop an assertion dialog
Sam Lantinga <slouken@libsdl.org>
parents:
3656
diff
changeset
|
341 } |
eaea59cee6f2
Leave fullscreen mode to pop an assertion dialog
Sam Lantinga <slouken@libsdl.org>
parents:
3656
diff
changeset
|
342 |
eaea59cee6f2
Leave fullscreen mode to pop an assertion dialog
Sam Lantinga <slouken@libsdl.org>
parents:
3656
diff
changeset
|
343 return state; |
3647
c5925cd41955
First pass at Ryan's assertion code, minor tweaks to come.
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
344 } |
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 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
|
348 |
c5925cd41955
First pass at Ryan's assertion code, minor tweaks to come.
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
349 SDL_assert_state |
3655
1cc7f0143c12
Moved SDL_FUNCTION out so it's always available, and added SDL_FILE and SDL_LINE
Sam Lantinga <slouken@libsdl.org>
parents:
3651
diff
changeset
|
350 SDL_ReportAssertion(SDL_assert_data *data, const char *func, const char *file, |
1cc7f0143c12
Moved SDL_FUNCTION out so it's always available, and added SDL_FILE and SDL_LINE
Sam Lantinga <slouken@libsdl.org>
parents:
3651
diff
changeset
|
351 int line) |
3647
c5925cd41955
First pass at Ryan's assertion code, minor tweaks to come.
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
352 { |
3661
22b6a0c7ea6e
Handle assertion failures during assertion handler.
Ryan C. Gordon <icculus@icculus.org>
parents:
3657
diff
changeset
|
353 static int assertion_running = 0; |
3662
6a0b3048f271
Handle assertion failures when SDL_Init() isn't called.
Ryan C. Gordon <icculus@icculus.org>
parents:
3661
diff
changeset
|
354 static SDL_SpinLock spinlock = 0; |
3661
22b6a0c7ea6e
Handle assertion failures during assertion handler.
Ryan C. Gordon <icculus@icculus.org>
parents:
3657
diff
changeset
|
355 SDL_assert_state state = SDL_ASSERTION_IGNORE; |
3647
c5925cd41955
First pass at Ryan's assertion code, minor tweaks to come.
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
356 |
3662
6a0b3048f271
Handle assertion failures when SDL_Init() isn't called.
Ryan C. Gordon <icculus@icculus.org>
parents:
3661
diff
changeset
|
357 SDL_AtomicLock(&spinlock); |
6a0b3048f271
Handle assertion failures when SDL_Init() isn't called.
Ryan C. Gordon <icculus@icculus.org>
parents:
3661
diff
changeset
|
358 if (assertion_mutex == NULL) { /* never called SDL_Init()? */ |
6a0b3048f271
Handle assertion failures when SDL_Init() isn't called.
Ryan C. Gordon <icculus@icculus.org>
parents:
3661
diff
changeset
|
359 assertion_mutex = SDL_CreateMutex(); |
6a0b3048f271
Handle assertion failures when SDL_Init() isn't called.
Ryan C. Gordon <icculus@icculus.org>
parents:
3661
diff
changeset
|
360 if (assertion_mutex == NULL) { |
6a0b3048f271
Handle assertion failures when SDL_Init() isn't called.
Ryan C. Gordon <icculus@icculus.org>
parents:
3661
diff
changeset
|
361 SDL_AtomicUnlock(&spinlock); |
6a0b3048f271
Handle assertion failures when SDL_Init() isn't called.
Ryan C. Gordon <icculus@icculus.org>
parents:
3661
diff
changeset
|
362 return SDL_ASSERTION_IGNORE; /* oh well, I guess. */ |
6a0b3048f271
Handle assertion failures when SDL_Init() isn't called.
Ryan C. Gordon <icculus@icculus.org>
parents:
3661
diff
changeset
|
363 } |
6a0b3048f271
Handle assertion failures when SDL_Init() isn't called.
Ryan C. Gordon <icculus@icculus.org>
parents:
3661
diff
changeset
|
364 } |
6a0b3048f271
Handle assertion failures when SDL_Init() isn't called.
Ryan C. Gordon <icculus@icculus.org>
parents:
3661
diff
changeset
|
365 SDL_AtomicUnlock(&spinlock); |
6a0b3048f271
Handle assertion failures when SDL_Init() isn't called.
Ryan C. Gordon <icculus@icculus.org>
parents:
3661
diff
changeset
|
366 |
3647
c5925cd41955
First pass at Ryan's assertion code, minor tweaks to come.
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
367 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
|
368 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
|
369 } |
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 /* 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
|
372 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
|
373 data->function = func; |
3655
1cc7f0143c12
Moved SDL_FUNCTION out so it's always available, and added SDL_FILE and SDL_LINE
Sam Lantinga <slouken@libsdl.org>
parents:
3651
diff
changeset
|
374 data->filename = file; |
1cc7f0143c12
Moved SDL_FUNCTION out so it's always available, and added SDL_FILE and SDL_LINE
Sam Lantinga <slouken@libsdl.org>
parents:
3651
diff
changeset
|
375 data->linenum = line; |
3647
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 |
c5925cd41955
First pass at Ryan's assertion code, minor tweaks to come.
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
378 SDL_AddAssertionToReport(data); |
c5925cd41955
First pass at Ryan's assertion code, minor tweaks to come.
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
379 |
c5925cd41955
First pass at Ryan's assertion code, minor tweaks to come.
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
380 data->trigger_count++; |
3661
22b6a0c7ea6e
Handle assertion failures during assertion handler.
Ryan C. Gordon <icculus@icculus.org>
parents:
3657
diff
changeset
|
381 |
22b6a0c7ea6e
Handle assertion failures during assertion handler.
Ryan C. Gordon <icculus@icculus.org>
parents:
3657
diff
changeset
|
382 assertion_running++; |
22b6a0c7ea6e
Handle assertion failures during assertion handler.
Ryan C. Gordon <icculus@icculus.org>
parents:
3657
diff
changeset
|
383 if (assertion_running > 1) { /* assert during assert! Abort. */ |
22b6a0c7ea6e
Handle assertion failures during assertion handler.
Ryan C. Gordon <icculus@icculus.org>
parents:
3657
diff
changeset
|
384 if (assertion_running == 2) { |
22b6a0c7ea6e
Handle assertion failures during assertion handler.
Ryan C. Gordon <icculus@icculus.org>
parents:
3657
diff
changeset
|
385 SDL_AbortAssertion(); |
22b6a0c7ea6e
Handle assertion failures during assertion handler.
Ryan C. Gordon <icculus@icculus.org>
parents:
3657
diff
changeset
|
386 } else if (assertion_running == 3) { /* Abort asserted! */ |
22b6a0c7ea6e
Handle assertion failures during assertion handler.
Ryan C. Gordon <icculus@icculus.org>
parents:
3657
diff
changeset
|
387 SDL_ExitProcess(42); |
22b6a0c7ea6e
Handle assertion failures during assertion handler.
Ryan C. Gordon <icculus@icculus.org>
parents:
3657
diff
changeset
|
388 } else { |
22b6a0c7ea6e
Handle assertion failures during assertion handler.
Ryan C. Gordon <icculus@icculus.org>
parents:
3657
diff
changeset
|
389 while (1) { /* do nothing but spin; what else can you do?! */ } |
22b6a0c7ea6e
Handle assertion failures during assertion handler.
Ryan C. Gordon <icculus@icculus.org>
parents:
3657
diff
changeset
|
390 } |
3647
c5925cd41955
First pass at Ryan's assertion code, minor tweaks to come.
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
391 } |
c5925cd41955
First pass at Ryan's assertion code, minor tweaks to come.
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
392 |
3661
22b6a0c7ea6e
Handle assertion failures during assertion handler.
Ryan C. Gordon <icculus@icculus.org>
parents:
3657
diff
changeset
|
393 if (!data->always_ignore) { |
22b6a0c7ea6e
Handle assertion failures during assertion handler.
Ryan C. Gordon <icculus@icculus.org>
parents:
3657
diff
changeset
|
394 state = SDL_PromptAssertion(data); |
22b6a0c7ea6e
Handle assertion failures during assertion handler.
Ryan C. Gordon <icculus@icculus.org>
parents:
3657
diff
changeset
|
395 } |
3647
c5925cd41955
First pass at Ryan's assertion code, minor tweaks to come.
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
396 |
c5925cd41955
First pass at Ryan's assertion code, minor tweaks to come.
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
397 switch (state) |
c5925cd41955
First pass at Ryan's assertion code, minor tweaks to come.
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
398 { |
c5925cd41955
First pass at Ryan's assertion code, minor tweaks to come.
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
399 case SDL_ASSERTION_ABORT: |
c5925cd41955
First pass at Ryan's assertion code, minor tweaks to come.
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
400 SDL_AbortAssertion(); |
c5925cd41955
First pass at Ryan's assertion code, minor tweaks to come.
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
401 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
|
402 |
c5925cd41955
First pass at Ryan's assertion code, minor tweaks to come.
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
403 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
|
404 state = SDL_ASSERTION_IGNORE; |
c5925cd41955
First pass at Ryan's assertion code, minor tweaks to come.
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
405 data->always_ignore = 1; |
c5925cd41955
First pass at Ryan's assertion code, minor tweaks to come.
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
406 break; |
c5925cd41955
First pass at Ryan's assertion code, minor tweaks to come.
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
407 |
c5925cd41955
First pass at Ryan's assertion code, minor tweaks to come.
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
408 case SDL_ASSERTION_IGNORE: |
c5925cd41955
First pass at Ryan's assertion code, minor tweaks to come.
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
409 case SDL_ASSERTION_RETRY: |
c5925cd41955
First pass at Ryan's assertion code, minor tweaks to come.
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
410 case SDL_ASSERTION_BREAK: |
c5925cd41955
First pass at Ryan's assertion code, minor tweaks to come.
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
411 break; /* macro handles these. */ |
c5925cd41955
First pass at Ryan's assertion code, minor tweaks to come.
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
412 } |
c5925cd41955
First pass at Ryan's assertion code, minor tweaks to come.
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
413 |
3661
22b6a0c7ea6e
Handle assertion failures during assertion handler.
Ryan C. Gordon <icculus@icculus.org>
parents:
3657
diff
changeset
|
414 assertion_running--; |
3647
c5925cd41955
First pass at Ryan's assertion code, minor tweaks to come.
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
415 SDL_UnlockMutex(assertion_mutex); |
c5925cd41955
First pass at Ryan's assertion code, minor tweaks to come.
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
416 |
c5925cd41955
First pass at Ryan's assertion code, minor tweaks to come.
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
417 return state; |
c5925cd41955
First pass at Ryan's assertion code, minor tweaks to come.
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
418 } |
c5925cd41955
First pass at Ryan's assertion code, minor tweaks to come.
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
419 |
c5925cd41955
First pass at Ryan's assertion code, minor tweaks to come.
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
420 #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
|
421 |
c5925cd41955
First pass at Ryan's assertion code, minor tweaks to come.
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
422 |
c5925cd41955
First pass at Ryan's assertion code, minor tweaks to come.
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
423 int SDL_AssertionsInit(void) |
c5925cd41955
First pass at Ryan's assertion code, minor tweaks to come.
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
424 { |
c5925cd41955
First pass at Ryan's assertion code, minor tweaks to come.
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
425 #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
|
426 assertion_mutex = SDL_CreateMutex(); |
c5925cd41955
First pass at Ryan's assertion code, minor tweaks to come.
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
427 if (assertion_mutex == NULL) { |
c5925cd41955
First pass at Ryan's assertion code, minor tweaks to come.
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
428 return -1; |
c5925cd41955
First pass at Ryan's assertion code, minor tweaks to come.
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
429 } |
c5925cd41955
First pass at Ryan's assertion code, minor tweaks to come.
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
430 #endif |
c5925cd41955
First pass at Ryan's assertion code, minor tweaks to come.
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
431 return 0; |
c5925cd41955
First pass at Ryan's assertion code, minor tweaks to come.
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
432 } |
c5925cd41955
First pass at Ryan's assertion code, minor tweaks to come.
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
433 |
c5925cd41955
First pass at Ryan's assertion code, minor tweaks to come.
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
434 void SDL_AssertionsQuit(void) |
c5925cd41955
First pass at Ryan's assertion code, minor tweaks to come.
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
435 { |
c5925cd41955
First pass at Ryan's assertion code, minor tweaks to come.
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
436 #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
|
437 SDL_GenerateAssertionReport(); |
c5925cd41955
First pass at Ryan's assertion code, minor tweaks to come.
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
438 SDL_DestroyMutex(assertion_mutex); |
c5925cd41955
First pass at Ryan's assertion code, minor tweaks to come.
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
439 assertion_mutex = NULL; |
c5925cd41955
First pass at Ryan's assertion code, minor tweaks to come.
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
440 #endif |
c5925cd41955
First pass at Ryan's assertion code, minor tweaks to come.
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
441 } |
c5925cd41955
First pass at Ryan's assertion code, minor tweaks to come.
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
442 |
c5925cd41955
First pass at Ryan's assertion code, minor tweaks to come.
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
443 /* vi: set ts=4 sw=4 expandtab: */ |