SDL_assert.h 23 KB

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