SDL 3.0
SDL_assert.h
Go to the documentation of this file.
1/*
2 Simple DirectMedia Layer
3 Copyright (C) 1997-2025 Sam Lantinga <slouken@libsdl.org>
4
5 This software is provided 'as-is', without any express or implied
6 warranty. In no event will the authors be held liable for any damages
7 arising from the use of this software.
8
9 Permission is granted to anyone to use this software for any purpose,
10 including commercial applications, and to alter it and redistribute it
11 freely, subject to the following restrictions:
12
13 1. The origin of this software must not be misrepresented; you must not
14 claim that you wrote the original software. If you use this software
15 in a product, an acknowledgment in the product documentation would be
16 appreciated but is not required.
17 2. Altered source versions must be plainly marked as such, and must not be
18 misrepresented as being the original software.
19 3. This notice may not be removed or altered from any source distribution.
20*/
21
22/**
23 * # CategoryAssert
24 *
25 * A helpful assertion macro!
26 *
27 * SDL assertions operate like your usual `assert` macro, but with some added
28 * features:
29 *
30 * - It uses a trick with the `sizeof` operator, so disabled assertions
31 * vaporize out of the compiled code, but variables only referenced in the
32 * assertion won't trigger compiler warnings about being unused.
33 * - It is safe to use with a dangling-else: `if (x) SDL_assert(y); else
34 * do_something();`
35 * - It works the same everywhere, instead of counting on various platforms'
36 * compiler and C runtime to behave.
37 * - It provides multiple levels of assertion (SDL_assert, SDL_assert_release,
38 * SDL_assert_paranoid) instead of a single all-or-nothing option.
39 * - It offers a variety of responses when an assertion fails (retry, trigger
40 * the debugger, abort the program, ignore the failure once, ignore it for
41 * the rest of the program's run).
42 * - It tries to show the user a dialog by default, if possible, but the app
43 * can provide a callback to handle assertion failures however they like.
44 * - It lets failed assertions be retried. Perhaps you had a network failure
45 * and just want to retry the test after plugging your network cable back
46 * in? You can.
47 * - It lets the user ignore an assertion failure, if there's a harmless
48 * problem that one can continue past.
49 * - It lets the user mark an assertion as ignored for the rest of the
50 * program's run; if there's a harmless problem that keeps popping up.
51 * - It provides statistics and data on all failed assertions to the app.
52 * - It allows the default assertion handler to be controlled with environment
53 * variables, in case an automated script needs to control it.
54 * - It can be used as an aid to Clang's static analysis; it will treat SDL
55 * assertions as universally true (under the assumption that you are serious
56 * about the asserted claims and that your debug builds will detect when
57 * these claims were wrong). This can help the analyzer avoid false
58 * positives.
59 *
60 * To use it: compile a debug build and just sprinkle around tests to check
61 * your code!
62 */
63
64#ifndef SDL_assert_h_
65#define SDL_assert_h_
66
67#include <SDL3/SDL_stdinc.h>
68
69#include <SDL3/SDL_begin_code.h>
70/* Set up for C function definitions, even when using C++ */
71#ifdef __cplusplus
72extern "C" {
73#endif
74
75#ifdef SDL_WIKI_DOCUMENTATION_SECTION
76
77/**
78 * The level of assertion aggressiveness.
79 *
80 * This value changes depending on compiler options and other preprocessor
81 * defines.
82 *
83 * It is currently one of the following values, but future SDL releases might
84 * add more:
85 *
86 * - 0: All SDL assertion macros are disabled.
87 * - 1: Release settings: SDL_assert disabled, SDL_assert_release enabled.
88 * - 2: Debug settings: SDL_assert and SDL_assert_release enabled.
89 * - 3: Paranoid settings: All SDL assertion macros enabled, including
90 * SDL_assert_paranoid.
91 *
92 * \since This macro is available since SDL 3.1.3.
93 */
94#define SDL_ASSERT_LEVEL SomeNumberBasedOnVariousFactors
95
96#elif !defined(SDL_ASSERT_LEVEL)
97#ifdef SDL_DEFAULT_ASSERT_LEVEL
98#define SDL_ASSERT_LEVEL SDL_DEFAULT_ASSERT_LEVEL
99#elif defined(_DEBUG) || defined(DEBUG) || \
100 (defined(__GNUC__) && !defined(__OPTIMIZE__))
101#define SDL_ASSERT_LEVEL 2
102#else
103#define SDL_ASSERT_LEVEL 1
104#endif
105#endif
106
107#ifdef SDL_WIKI_DOCUMENTATION_SECTION
108
109/**
110 * Attempt to tell an attached debugger to pause.
111 *
112 * This allows an app to programmatically halt ("break") the debugger as if it
113 * had hit a breakpoint, allowing the developer to examine program state, etc.
114 *
115 * This is a macro--not a function--so that the debugger breaks on the source
116 * code line that used SDL_TriggerBreakpoint and not in some random guts of
117 * SDL. SDL_assert uses this macro for the same reason.
118 *
119 * If the program is not running under a debugger, SDL_TriggerBreakpoint will
120 * likely terminate the app, possibly without warning. If the current platform
121 * isn't supported (SDL doesn't know how to trigger a breakpoint), this macro
122 * does nothing.
123 *
124 * \threadsafety It is safe to call this macro from any thread.
125 *
126 * \since This macro is available since SDL 3.1.3.
127 */
128#define SDL_TriggerBreakpoint() TriggerABreakpointInAPlatformSpecificManner
129
130#elif defined(_MSC_VER)
131 /* Don't include intrin.h here because it contains C++ code */
132 extern void __cdecl __debugbreak(void);
133 #define SDL_TriggerBreakpoint() __debugbreak()
134#elif defined(ANDROID)
135 #include <assert.h>
136 #define SDL_TriggerBreakpoint() assert(0)
137#elif SDL_HAS_BUILTIN(__builtin_debugtrap)
138 #define SDL_TriggerBreakpoint() __builtin_debugtrap()
139#elif (defined(__GNUC__) || defined(__clang__)) && (defined(__i386__) || defined(__x86_64__))
140 #define SDL_TriggerBreakpoint() __asm__ __volatile__ ( "int $3\n\t" )
141#elif (defined(__GNUC__) || defined(__clang__)) && defined(__riscv)
142 #define SDL_TriggerBreakpoint() __asm__ __volatile__ ( "ebreak\n\t" )
143#elif ( defined(SDL_PLATFORM_APPLE) && (defined(__arm64__) || defined(__aarch64__)) ) /* this might work on other ARM targets, but this is a known quantity... */
144 #define SDL_TriggerBreakpoint() __asm__ __volatile__ ( "brk #22\n\t" )
145#elif defined(SDL_PLATFORM_APPLE) && defined(__arm__)
146 #define SDL_TriggerBreakpoint() __asm__ __volatile__ ( "bkpt #22\n\t" )
147#elif defined(_WIN32) && ((defined(__GNUC__) || defined(__clang__)) && (defined(__arm64__) || defined(__aarch64__)) )
148 #define SDL_TriggerBreakpoint() __asm__ __volatile__ ( "brk #0xF000\n\t" )
149#elif defined(__386__) && defined(__WATCOMC__)
150 #define SDL_TriggerBreakpoint() { _asm { int 0x03 } }
151#elif defined(HAVE_SIGNAL_H) && !defined(__WATCOMC__)
152 #include <signal.h>
153 #define SDL_TriggerBreakpoint() raise(SIGTRAP)
154#else
155 /* How do we trigger breakpoints on this platform? */
156 #define SDL_TriggerBreakpoint()
157#endif
158
159#ifdef SDL_WIKI_DOCUMENTATION_SECTION
160
161/**
162 * A macro that reports the current function being compiled.
163 *
164 * If SDL can't figure how the compiler reports this, it will use "???".
165 *
166 * \since This macro is available since SDL 3.1.3.
167 */
168#define SDL_FUNCTION __FUNCTION__
169
170#elif defined(__STDC_VERSION__) && (__STDC_VERSION__ >= 199901L) /* C99 supports __func__ as a standard. */
171# define SDL_FUNCTION __func__
172#elif ((defined(__GNUC__) && (__GNUC__ >= 2)) || defined(_MSC_VER) || defined (__WATCOMC__))
173# define SDL_FUNCTION __FUNCTION__
174#else
175# define SDL_FUNCTION "???"
176#endif
177
178/**
179 * A macro that reports the current file being compiled.
180 *
181 * \since This macro is available since SDL 3.1.3.
182 */
183#define SDL_FILE __FILE__
184
185/**
186 * A macro that reports the current line number of the file being compiled.
187 *
188 * \since This macro is available since SDL 3.1.3.
189 */
190#define SDL_LINE __LINE__
191
192/*
193sizeof (x) makes the compiler still parse the expression even without
194assertions enabled, so the code is always checked at compile time, but
195doesn't actually generate code for it, so there are no side effects or
196expensive checks at run time, just the constant size of what x WOULD be,
197which presumably gets optimized out as unused.
198This also solves the problem of...
199
200 int somevalue = blah();
201 SDL_assert(somevalue == 1);
202
203...which would cause compiles to complain that somevalue is unused if we
204disable assertions.
205*/
206
207#ifdef SDL_WIKI_DOCUMENTATION_SECTION
208
209/**
210 * A macro for wrapping code in `do {} while (0);` without compiler warnings.
211 *
212 * Visual Studio with really aggressive warnings enabled needs this to avoid
213 * compiler complaints.
214 *
215 * the `do {} while (0);` trick is useful for wrapping code in a macro that
216 * may or may not be a single statement, to avoid various C language
217 * accidents.
218 *
219 * To use:
220 *
221 * ```c
222 * do { SomethingOnce(); } while (SDL_NULL_WHILE_LOOP_CONDITION (0));
223 * ```
224 *
225 * \since This macro is available since SDL 3.1.3.
226 */
227#define SDL_NULL_WHILE_LOOP_CONDITION (0)
228
229#elif defined(_MSC_VER) /* Avoid /W4 warnings. */
230/* "while (0,0)" fools Microsoft's compiler's /W4 warning level into thinking
231 this condition isn't constant. And looks like an owl's face! */
232#define SDL_NULL_WHILE_LOOP_CONDITION (0,0)
233#else
234#define SDL_NULL_WHILE_LOOP_CONDITION (0)
235#endif
236
237/**
238 * The macro used when an assertion is disabled.
239 *
240 * This isn't for direct use by apps, but this is the code that is inserted
241 * when an SDL_assert is disabled (perhaps in a release build).
242 *
243 * The code does nothing, but wraps `condition` in a sizeof operator, which
244 * generates no code and has no side effects, but avoid compiler warnings
245 * about unused variables.
246 *
247 * \param condition the condition to assert (but not actually run here).
248 *
249 * \since This macro is available since SDL 3.1.3.
250 */
251#define SDL_disabled_assert(condition) \
252 do { (void) sizeof ((condition)); } while (SDL_NULL_WHILE_LOOP_CONDITION)
253
254/**
255 * Possible outcomes from a triggered assertion.
256 *
257 * When an enabled assertion triggers, it may call the assertion handler
258 * (possibly one provided by the app via SDL_SetAssertionHandler), which will
259 * return one of these values, possibly after asking the user.
260 *
261 * Then SDL will respond based on this outcome (loop around to retry the
262 * condition, try to break in a debugger, kill the program, or ignore the
263 * problem).
264 *
265 * \since This enum is available since SDL 3.1.3.
266 */
267typedef enum SDL_AssertState
268{
269 SDL_ASSERTION_RETRY, /**< Retry the assert immediately. */
270 SDL_ASSERTION_BREAK, /**< Make the debugger trigger a breakpoint. */
271 SDL_ASSERTION_ABORT, /**< Terminate the program. */
272 SDL_ASSERTION_IGNORE, /**< Ignore the assert. */
273 SDL_ASSERTION_ALWAYS_IGNORE /**< Ignore the assert from now on. */
275
276/**
277 * Information about an assertion failure.
278 *
279 * This structure is filled in with information about a triggered assertion,
280 * used by the assertion handler, then added to the assertion report. This is
281 * returned as a linked list from SDL_GetAssertionReport().
282 *
283 * \since This struct is available since SDL 3.1.3.
284 */
285typedef struct SDL_AssertData
286{
287 bool always_ignore; /**< true if app should always continue when assertion is triggered. */
288 unsigned int trigger_count; /**< Number of times this assertion has been triggered. */
289 const char *condition; /**< A string of this assert's test code. */
290 const char *filename; /**< The source file where this assert lives. */
291 int linenum; /**< The line in `filename` where this assert lives. */
292 const char *function; /**< The name of the function where this assert lives. */
293 const struct SDL_AssertData *next; /**< next item in the linked list. */
295
296/**
297 * Never call this directly.
298 *
299 * Use the SDL_assert macros instead.
300 *
301 * \param data assert data structure.
302 * \param func function name.
303 * \param file file name.
304 * \param line line number.
305 * \returns assert state.
306 *
307 * \threadsafety It is safe to call this function from any thread.
308 *
309 * \since This function is available since SDL 3.1.3.
310 */
311extern SDL_DECLSPEC SDL_AssertState SDLCALL SDL_ReportAssertion(SDL_AssertData *data,
312 const char *func,
313 const char *file, int line) SDL_ANALYZER_NORETURN;
314
315
316#ifdef SDL_WIKI_DOCUMENTATION_SECTION
317
318/**
319 * The macro used when an assertion triggers a breakpoint.
320 *
321 * This isn't for direct use by apps; use SDL_assert or SDL_TriggerBreakpoint
322 * instead.
323 *
324 * \since This macro is available since SDL 3.1.3.
325 */
326#define SDL_AssertBreakpoint() SDL_TriggerBreakpoint()
327
328#elif !defined(SDL_AssertBreakpoint)
329# if defined(ANDROID) && defined(assert)
330 /* Define this as empty in case assert() is defined as SDL_assert */
331# define SDL_AssertBreakpoint()
332# else
333# define SDL_AssertBreakpoint() SDL_TriggerBreakpoint()
334# endif
335#endif /* !SDL_AssertBreakpoint */
336
337/**
338 * The macro used when an assertion is enabled.
339 *
340 * This isn't for direct use by apps, but this is the code that is inserted
341 * when an SDL_assert is enabled.
342 *
343 * The `do {} while(0)` avoids dangling else problems:
344 *
345 * ```c
346 * if (x) SDL_assert(y); else blah();
347 * ```
348 *
349 * ... without the do/while, the "else" could attach to this macro's "if". We
350 * try to handle just the minimum we need here in a macro...the loop, the
351 * static vars, and break points. The heavy lifting is handled in
352 * SDL_ReportAssertion().
353 *
354 * \param condition the condition to assert.
355 *
356 * \since This macro is available since SDL 3.1.3.
357 */
358#define SDL_enabled_assert(condition) \
359 do { \
360 while ( !(condition) ) { \
361 static struct SDL_AssertData sdl_assert_data = { 0, 0, #condition, 0, 0, 0, 0 }; \
362 const SDL_AssertState sdl_assert_state = SDL_ReportAssertion(&sdl_assert_data, SDL_FUNCTION, SDL_FILE, SDL_LINE); \
363 if (sdl_assert_state == SDL_ASSERTION_RETRY) { \
364 continue; /* go again. */ \
365 } else if (sdl_assert_state == SDL_ASSERTION_BREAK) { \
366 SDL_AssertBreakpoint(); \
367 } \
368 break; /* not retrying. */ \
369 } \
370 } while (SDL_NULL_WHILE_LOOP_CONDITION)
371
372#ifdef SDL_WIKI_DOCUMENTATION_SECTION
373
374/**
375 * An assertion test that is normally performed only in debug builds.
376 *
377 * This macro is enabled when the SDL_ASSERT_LEVEL is >= 2, otherwise it is
378 * disabled. This is meant to only do these tests in debug builds, so they can
379 * tend to be more expensive, and they are meant to bring everything to a halt
380 * when they fail, with the programmer there to assess the problem.
381 *
382 * In short: you can sprinkle these around liberally and assume they will
383 * evaporate out of the build when building for end-users.
384 *
385 * When assertions are disabled, this wraps `condition` in a `sizeof`
386 * operator, which means any function calls and side effects will not run, but
387 * the compiler will not complain about any otherwise-unused variables that
388 * are only referenced in the assertion.
389 *
390 * One can set the environment variable "SDL_ASSERT" to one of several strings
391 * ("abort", "break", "retry", "ignore", "always_ignore") to force a default
392 * behavior, which may be desirable for automation purposes. If your platform
393 * requires GUI interfaces to happen on the main thread but you're debugging
394 * an assertion in a background thread, it might be desirable to set this to
395 * "break" so that your debugger takes control as soon as assert is triggered,
396 * instead of risking a bad UI interaction (deadlock, etc) in the application.
397 *
398 * \param condition boolean value to test.
399 *
400 * \threadsafety It is safe to call this macro from any thread.
401 *
402 * \since This macro is available since SDL 3.1.3.
403 */
404#define SDL_assert(condition) if (assertion_enabled && (condition)) { trigger_assertion; }
405
406/**
407 * An assertion test that is performed even in release builds.
408 *
409 * This macro is enabled when the SDL_ASSERT_LEVEL is >= 1, otherwise it is
410 * disabled. This is meant to be for tests that are cheap to make and
411 * extremely unlikely to fail; generally it is frowned upon to have an
412 * assertion failure in a release build, so these assertions generally need to
413 * be of more than life-and-death importance if there's a chance they might
414 * trigger. You should almost always consider handling these cases more
415 * gracefully than an assert allows.
416 *
417 * When assertions are disabled, this wraps `condition` in a `sizeof`
418 * operator, which means any function calls and side effects will not run, but
419 * the compiler will not complain about any otherwise-unused variables that
420 * are only referenced in the assertion.
421 *
422 * One can set the environment variable "SDL_ASSERT" to one of several strings
423 * ("abort", "break", "retry", "ignore", "always_ignore") to force a default
424 * behavior, which may be desirable for automation purposes. If your platform
425 * requires GUI interfaces to happen on the main thread but you're debugging
426 * an assertion in a background thread, it might be desirable to set this to
427 * "break" so that your debugger takes control as soon as assert is triggered,
428 * instead of risking a bad UI interaction (deadlock, etc) in the application.
429 * *
430 *
431 * \param condition boolean value to test.
432 *
433 * \threadsafety It is safe to call this macro from any thread.
434 *
435 * \since This macro is available since SDL 3.1.3.
436 */
437#define SDL_assert_release(condition) SDL_disabled_assert(condition)
438
439/**
440 * An assertion test that is performed only when built with paranoid settings.
441 *
442 * This macro is enabled when the SDL_ASSERT_LEVEL is >= 3, otherwise it is
443 * disabled. This is a higher level than both release and debug, so these
444 * tests are meant to be expensive and only run when specifically looking for
445 * extremely unexpected failure cases in a special build.
446 *
447 * When assertions are disabled, this wraps `condition` in a `sizeof`
448 * operator, which means any function calls and side effects will not run, but
449 * the compiler will not complain about any otherwise-unused variables that
450 * are only referenced in the assertion.
451 *
452 * One can set the environment variable "SDL_ASSERT" to one of several strings
453 * ("abort", "break", "retry", "ignore", "always_ignore") to force a default
454 * behavior, which may be desirable for automation purposes. If your platform
455 * requires GUI interfaces to happen on the main thread but you're debugging
456 * an assertion in a background thread, it might be desirable to set this to
457 * "break" so that your debugger takes control as soon as assert is triggered,
458 * instead of risking a bad UI interaction (deadlock, etc) in the application.
459 *
460 * \param condition boolean value to test.
461 *
462 * \threadsafety It is safe to call this macro from any thread.
463 *
464 * \since This macro is available since SDL 3.1.3.
465 */
466#define SDL_assert_paranoid(condition) SDL_disabled_assert(condition)
467
468/* Enable various levels of assertions. */
469#elif SDL_ASSERT_LEVEL == 0 /* assertions disabled */
470# define SDL_assert(condition) SDL_disabled_assert(condition)
471# define SDL_assert_release(condition) SDL_disabled_assert(condition)
472# define SDL_assert_paranoid(condition) SDL_disabled_assert(condition)
473#elif SDL_ASSERT_LEVEL == 1 /* release settings. */
474# define SDL_assert(condition) SDL_disabled_assert(condition)
475# define SDL_assert_release(condition) SDL_enabled_assert(condition)
476# define SDL_assert_paranoid(condition) SDL_disabled_assert(condition)
477#elif SDL_ASSERT_LEVEL == 2 /* debug settings. */
478# define SDL_assert(condition) SDL_enabled_assert(condition)
479# define SDL_assert_release(condition) SDL_enabled_assert(condition)
480# define SDL_assert_paranoid(condition) SDL_disabled_assert(condition)
481#elif SDL_ASSERT_LEVEL == 3 /* paranoid settings. */
482# define SDL_assert(condition) SDL_enabled_assert(condition)
483# define SDL_assert_release(condition) SDL_enabled_assert(condition)
484# define SDL_assert_paranoid(condition) SDL_enabled_assert(condition)
485#else
486# error Unknown assertion level.
487#endif
488
489/**
490 * An assertion test that is always performed.
491 *
492 * This macro is always enabled no matter what SDL_ASSERT_LEVEL is set to. You
493 * almost never want to use this, as it could trigger on an end-user's system,
494 * crashing your program.
495 *
496 * One can set the environment variable "SDL_ASSERT" to one of several strings
497 * ("abort", "break", "retry", "ignore", "always_ignore") to force a default
498 * behavior, which may be desirable for automation purposes. If your platform
499 * requires GUI interfaces to happen on the main thread but you're debugging
500 * an assertion in a background thread, it might be desirable to set this to
501 * "break" so that your debugger takes control as soon as assert is triggered,
502 * instead of risking a bad UI interaction (deadlock, etc) in the application.
503 *
504 * \param condition boolean value to test.
505 *
506 * \threadsafety It is safe to call this macro from any thread.
507 *
508 * \since This macro is available since SDL 3.1.3.
509 */
510#define SDL_assert_always(condition) SDL_enabled_assert(condition)
511
512
513/**
514 * A callback that fires when an SDL assertion fails.
515 *
516 * \param data a pointer to the SDL_AssertData structure corresponding to the
517 * current assertion.
518 * \param userdata what was passed as `userdata` to SDL_SetAssertionHandler().
519 * \returns an SDL_AssertState value indicating how to handle the failure.
520 *
521 * \threadsafety This callback may be called from any thread that triggers an
522 * assert at any time.
523 *
524 * \since This datatype is available since SDL 3.1.3.
525 */
527 const SDL_AssertData *data, void *userdata);
528
529/**
530 * Set an application-defined assertion handler.
531 *
532 * This function allows an application to show its own assertion UI and/or
533 * force the response to an assertion failure. If the application doesn't
534 * provide this, SDL will try to do the right thing, popping up a
535 * system-specific GUI dialog, and probably minimizing any fullscreen windows.
536 *
537 * This callback may fire from any thread, but it runs wrapped in a mutex, so
538 * it will only fire from one thread at a time.
539 *
540 * This callback is NOT reset to SDL's internal handler upon SDL_Quit()!
541 *
542 * \param handler the SDL_AssertionHandler function to call when an assertion
543 * fails or NULL for the default handler.
544 * \param userdata a pointer that is passed to `handler`.
545 *
546 * \threadsafety It is safe to call this function from any thread.
547 *
548 * \since This function is available since SDL 3.1.3.
549 *
550 * \sa SDL_GetAssertionHandler
551 */
552extern SDL_DECLSPEC void SDLCALL SDL_SetAssertionHandler(
553 SDL_AssertionHandler handler,
554 void *userdata);
555
556/**
557 * Get the default assertion handler.
558 *
559 * This returns the function pointer that is called by default when an
560 * assertion is triggered. This is an internal function provided by SDL, that
561 * is used for assertions when SDL_SetAssertionHandler() hasn't been used to
562 * provide a different function.
563 *
564 * \returns the default SDL_AssertionHandler that is called when an assert
565 * triggers.
566 *
567 * \threadsafety It is safe to call this function from any thread.
568 *
569 * \since This function is available since SDL 3.1.3.
570 *
571 * \sa SDL_GetAssertionHandler
572 */
573extern SDL_DECLSPEC SDL_AssertionHandler SDLCALL SDL_GetDefaultAssertionHandler(void);
574
575/**
576 * Get the current assertion handler.
577 *
578 * This returns the function pointer that is called when an assertion is
579 * triggered. This is either the value last passed to
580 * SDL_SetAssertionHandler(), or if no application-specified function is set,
581 * is equivalent to calling SDL_GetDefaultAssertionHandler().
582 *
583 * The parameter `puserdata` is a pointer to a void*, which will store the
584 * "userdata" pointer that was passed to SDL_SetAssertionHandler(). This value
585 * will always be NULL for the default handler. If you don't care about this
586 * data, it is safe to pass a NULL pointer to this function to ignore it.
587 *
588 * \param puserdata pointer which is filled with the "userdata" pointer that
589 * was passed to SDL_SetAssertionHandler().
590 * \returns the SDL_AssertionHandler that is called when an assert triggers.
591 *
592 * \threadsafety It is safe to call this function from any thread.
593 *
594 * \since This function is available since SDL 3.1.3.
595 *
596 * \sa SDL_SetAssertionHandler
597 */
598extern SDL_DECLSPEC SDL_AssertionHandler SDLCALL SDL_GetAssertionHandler(void **puserdata);
599
600/**
601 * Get a list of all assertion failures.
602 *
603 * This function gets all assertions triggered since the last call to
604 * SDL_ResetAssertionReport(), or the start of the program.
605 *
606 * The proper way to examine this data looks something like this:
607 *
608 * ```c
609 * const SDL_AssertData *item = SDL_GetAssertionReport();
610 * while (item) {
611 * printf("'%s', %s (%s:%d), triggered %u times, always ignore: %s.\\n",
612 * item->condition, item->function, item->filename,
613 * item->linenum, item->trigger_count,
614 * item->always_ignore ? "yes" : "no");
615 * item = item->next;
616 * }
617 * ```
618 *
619 * \returns a list of all failed assertions or NULL if the list is empty. This
620 * memory should not be modified or freed by the application. This
621 * pointer remains valid until the next call to SDL_Quit() or
622 * SDL_ResetAssertionReport().
623 *
624 * \threadsafety This function is not thread safe. Other threads calling
625 * SDL_ResetAssertionReport() simultaneously, may render the
626 * returned pointer invalid.
627 *
628 * \since This function is available since SDL 3.1.3.
629 *
630 * \sa SDL_ResetAssertionReport
631 */
632extern SDL_DECLSPEC const SDL_AssertData * SDLCALL SDL_GetAssertionReport(void);
633
634/**
635 * Clear the list of all assertion failures.
636 *
637 * This function will clear the list of all assertions triggered up to that
638 * point. Immediately following this call, SDL_GetAssertionReport will return
639 * no items. In addition, any previously-triggered assertions will be reset to
640 * a trigger_count of zero, and their always_ignore state will be false.
641 *
642 * \threadsafety This function is not thread safe. Other threads triggering an
643 * assertion, or simultaneously calling this function may cause
644 * memory leaks or crashes.
645 *
646 * \since This function is available since SDL 3.1.3.
647 *
648 * \sa SDL_GetAssertionReport
649 */
650extern SDL_DECLSPEC void SDLCALL SDL_ResetAssertionReport(void);
651
652/* Ends C function definitions when using C++ */
653#ifdef __cplusplus
654}
655#endif
656#include <SDL3/SDL_close_code.h>
657
658#endif /* SDL_assert_h_ */
SDL_AssertState
Definition SDL_assert.h:268
@ SDL_ASSERTION_RETRY
Definition SDL_assert.h:269
@ SDL_ASSERTION_ABORT
Definition SDL_assert.h:271
@ SDL_ASSERTION_IGNORE
Definition SDL_assert.h:272
@ SDL_ASSERTION_BREAK
Definition SDL_assert.h:270
@ SDL_ASSERTION_ALWAYS_IGNORE
Definition SDL_assert.h:273
SDL_AssertState(* SDL_AssertionHandler)(const SDL_AssertData *data, void *userdata)
Definition SDL_assert.h:526
SDL_AssertState SDL_ReportAssertion(SDL_AssertData *data, const char *func, const char *file, int line) SDL_ANALYZER_NORETURN
const SDL_AssertData * SDL_GetAssertionReport(void)
void SDL_ResetAssertionReport(void)
void SDL_SetAssertionHandler(SDL_AssertionHandler handler, void *userdata)
SDL_AssertionHandler SDL_GetDefaultAssertionHandler(void)
SDL_AssertionHandler SDL_GetAssertionHandler(void **puserdata)
#define SDL_ANALYZER_NORETURN
const struct SDL_AssertData * next
Definition SDL_assert.h:293
unsigned int trigger_count
Definition SDL_assert.h:288
const char * function
Definition SDL_assert.h:292
const char * filename
Definition SDL_assert.h:290
const char * condition
Definition SDL_assert.h:289