SDL_assert.h File Reference
`#include "SDL_stdinc.h"`
`#include "begin_code.h"`
`#include <signal.h>`
`#include "close_code.h"`
Include dependency graph for SDL_assert.h:
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

## Data Structures

struct | SDL_AssertData

## Macros

#define | SDL_ASSERT_LEVEL 1
#define | SDL_TriggerBreakpoint()
#define | SDL_FUNCTION "???"
#define | SDL_FILE __FILE__
#define | SDL_LINE __LINE__
#define | SDL_NULL_WHILE_LOOP_CONDITION (0)
#define | SDL_disabled_assert(condition)
#define | SDL_enabled_assert(condition)
#define | SDL_assert(condition)
#define | SDL_assert_release(condition)
#define | SDL_assert_paranoid(condition)
#define | SDL_assert_always(condition)
#define | SDL_assert_state SDL_AssertState
#define | SDL_assert_data SDL_AssertData

## Typedefs

typedef SDL_AssertState(* | SDL_AssertionHandler) (const SDL_AssertData *data, void *userdata)

## Enumerations

enum | SDL_AssertState { SDL_ASSERTION_RETRY , SDL_ASSERTION_BREAK , SDL_ASSERTION_ABORT , SDL_ASSERTION_IGNORE , SDL_ASSERTION_ALWAYS_IGNORE }

## Functions

SDL_AssertState | SDL_ReportAssertion (SDL_AssertData *, const char *, const char *, int)
void | SDL_SetAssertionHandler (SDL_AssertionHandler handler, void *userdata)
SDL_AssertionHandler | SDL_GetDefaultAssertionHandler (void)
SDL_AssertionHandler | SDL_GetAssertionHandler (void **puserdata)
const SDL_AssertData * | SDL_GetAssertionReport (void)
void | SDL_ResetAssertionReport (void)

## Macro Definition Documentation

## SDL_assert

#define SDL_assert | ( |  | condition | ) |

Value:
SDL_disabled_assert(condition)
SDL_disabled_assert
#define SDL_disabled_assert(condition)
Definition SDL_assert.h:109

Definition at line 169 of file SDL_assert.h.

## SDL_assert_always

#define SDL_assert_always | ( |  | condition | ) |

Value:
SDL_enabled_assert(condition)
SDL_enabled_assert
#define SDL_enabled_assert(condition)
Definition SDL_assert.h:153

Definition at line 189 of file SDL_assert.h.

## SDL_assert_data

#define SDL_assert_data SDL_AssertData

Definition at line 313 of file SDL_assert.h.

## SDL_ASSERT_LEVEL

#define SDL_ASSERT_LEVEL 1

Definition at line 40 of file SDL_assert.h.

## SDL_assert_paranoid

#define SDL_assert_paranoid | ( |  | condition | ) |

Value:
SDL_disabled_assert(condition)

Definition at line 171 of file SDL_assert.h.

## SDL_assert_release

#define SDL_assert_release | ( |  | condition | ) |

Value:
SDL_disabled_assert(condition)

Definition at line 170 of file SDL_assert.h.

## SDL_assert_state

#define SDL_assert_state SDL_AssertState

Definition at line 312 of file SDL_assert.h.

## SDL_disabled_assert

#define SDL_disabled_assert | ( |  | condition | ) |

Value:
do { (void) sizeof ((condition)); } while (SDL_NULL_WHILE_LOOP_CONDITION)
SDL_NULL_WHILE_LOOP_CONDITION
#define SDL_NULL_WHILE_LOOP_CONDITION
Definition SDL_assert.h:106

Definition at line 109 of file SDL_assert.h.

#define SDL_disabled_assert(condition) \
do { (void) sizeof ((condition)); } while (SDL_NULL_WHILE_LOOP_CONDITION)

## SDL_enabled_assert

#define SDL_enabled_assert | ( |  | condition | ) |

Value:
do { \
while ( !(condition) ) { \
static struct SDL_AssertData sdl_assert_data = { 0, 0, #condition, NULL, 0, NULL, NULL }; \
const SDL_AssertState sdl_assert_state = SDL_ReportAssertion(&sdl_assert_data, SDL_FUNCTION, SDL_FILE, SDL_LINE); \
if (sdl_assert_state == SDL_ASSERTION_RETRY) { \
continue; /* go again. */ \
} else if (sdl_assert_state == SDL_ASSERTION_BREAK) { \
SDL_TriggerBreakpoint(); \
} \
break; /* not retrying. */ \
} \
} while (SDL_NULL_WHILE_LOOP_CONDITION)
SDL_AssertState
SDL_AssertState
Definition SDL_assert.h:113
SDL_ASSERTION_RETRY
@ SDL_ASSERTION_RETRY
Definition SDL_assert.h:114
SDL_ASSERTION_BREAK
@ SDL_ASSERTION_BREAK
Definition SDL_assert.h:115
SDL_FILE
#define SDL_FILE
Definition SDL_assert.h:83
SDL_ReportAssertion
SDL_AssertState SDL_ReportAssertion(SDL_AssertData *, const char *, const char *, int)
SDL_FUNCTION
#define SDL_FUNCTION
Definition SDL_assert.h:81
SDL_LINE
#define SDL_LINE
Definition SDL_assert.h:84
NULL
#define NULL
Definition begin_code.h:165
SDL_AssertData
Definition SDL_assert.h:122

Definition at line 153 of file SDL_assert.h.

#define SDL_enabled_assert(condition) \
do { \
while ( !(condition) ) { \
static struct SDL_AssertData sdl_assert_data = { 0, 0, #condition, NULL, 0, NULL, NULL }; \
const SDL_AssertState sdl_assert_state = SDL_ReportAssertion(&sdl_assert_data, SDL_FUNCTION, SDL_FILE, SDL_LINE); \
if (sdl_assert_state == SDL_ASSERTION_RETRY) { \
continue; /* go again. */ \
} else if (sdl_assert_state == SDL_ASSERTION_BREAK) { \
SDL_TriggerBreakpoint(); \
} \
break; /* not retrying. */ \
} \
} while (SDL_NULL_WHILE_LOOP_CONDITION)

## SDL_FILE

#define SDL_FILE __FILE__

Definition at line 83 of file SDL_assert.h.

## SDL_FUNCTION

#define SDL_FUNCTION "???"

Definition at line 81 of file SDL_assert.h.

## SDL_LINE

#define SDL_LINE __LINE__

Definition at line 84 of file SDL_assert.h.

## SDL_NULL_WHILE_LOOP_CONDITION

#define SDL_NULL_WHILE_LOOP_CONDITION (0)

Definition at line 106 of file SDL_assert.h.

## SDL_TriggerBreakpoint

#define SDL_TriggerBreakpoint | ( |  | ) |

Value:
raise(SIGTRAP)

Definition at line 70 of file SDL_assert.h.

## Typedef Documentation

## SDL_AssertionHandler

typedef SDL_AssertState(* SDL_AssertionHandler) (const SDL_AssertData *data, void *userdata)

A callback that fires when an SDL assertion fails.

Parameters

  data | a pointer to the SDL_AssertData structure corresponding to the current assertion.
  userdata | what was passed as userdata to SDL_SetAssertionHandler().

Returns
  an SDL_AssertState value indicating how to handle the failure.

Definition at line 200 of file SDL_assert.h.

## Enumeration Type Documentation

## SDL_AssertState

enum SDL_AssertState

Enumerator
SDL_ASSERTION_RETRY | Retry the assert immediately.
SDL_ASSERTION_BREAK | Make the debugger trigger a breakpoint.
SDL_ASSERTION_ABORT | Terminate the program.
SDL_ASSERTION_IGNORE | Ignore the assert.
SDL_ASSERTION_ALWAYS_IGNORE | Ignore the assert from now on.

Definition at line 112 of file SDL_assert.h.

{
SDL_ASSERTION_RETRY, /**< Retry the assert immediately. */
SDL_ASSERTION_BREAK, /**< Make the debugger trigger a breakpoint. */
SDL_ASSERTION_ABORT, /**< Terminate the program. */
SDL_ASSERTION_IGNORE, /**< Ignore the assert. */
SDL_ASSERTION_ALWAYS_IGNORE /**< Ignore the assert from now on. */
} SDL_AssertState;
SDL_ASSERTION_ABORT
@ SDL_ASSERTION_ABORT
Definition SDL_assert.h:116
SDL_ASSERTION_IGNORE
@ SDL_ASSERTION_IGNORE
Definition SDL_assert.h:117
SDL_ASSERTION_ALWAYS_IGNORE
@ SDL_ASSERTION_ALWAYS_IGNORE
Definition SDL_assert.h:118

## Function Documentation

## SDL_GetAssertionHandler()

SDL_AssertionHandler SDL_GetAssertionHandler | ( | void ** | puserdata | ) |

extern

Get the current assertion handler.

This returns the function pointer that is called when an assertion is triggered. This is either the value last passed to SDL_SetAssertionHandler(), or if no application-specified function is set, is equivalent to calling SDL_GetDefaultAssertionHandler().

The parameter puserdata is a pointer to a void*, which will store the "userdata" pointer that was passed to SDL_SetAssertionHandler(). This value will always be NULL for the default handler. If you don't care about this data, it is safe to pass a NULL pointer to this function to ignore it.

Parameters

  puserdata | pointer which is filled with the "userdata" pointer that was passed to SDL_SetAssertionHandler().

Returns
  the SDL_AssertionHandler that is called when an assert triggers.

Since
  This function is available since SDL 2.0.2.

See also
  SDL_SetAssertionHandler

## SDL_GetAssertionReport()

const SDL_AssertData * SDL_GetAssertionReport | ( | void |  | ) |

extern

Get a list of all assertion failures.

This function gets all assertions triggered since the last call to SDL_ResetAssertionReport(), or the start of the program.

The proper way to examine this data looks something like this:

const SDL_AssertData *item = SDL_GetAssertionReport();
while (item) {
printf("'%s', %s (%s:%d), triggered %u times, always ignore: %s.\\n",
item->condition, item->function, item->filename,
item->linenum, item->trigger_count,
item->always_ignore ? "yes" : "no");
item = item->next;
}
SDL_GetAssertionReport
const SDL_AssertData * SDL_GetAssertionReport(void)
SDL_AssertData::next
const struct SDL_AssertData * next
Definition SDL_assert.h:129
SDL_AssertData::trigger_count
unsigned int trigger_count
Definition SDL_assert.h:124
SDL_AssertData::function
const char * function
Definition SDL_assert.h:128
SDL_AssertData::always_ignore
int always_ignore
Definition SDL_assert.h:123
SDL_AssertData::filename
const char * filename
Definition SDL_assert.h:126
SDL_AssertData::linenum
int linenum
Definition SDL_assert.h:127
SDL_AssertData::condition
const char * condition
Definition SDL_assert.h:125

Returns
  a list of all failed assertions or NULL if the list is empty. This memory should not be modified or freed by the application.

Since
  This function is available since SDL 2.0.0.

See also
  SDL_ResetAssertionReport

## SDL_GetDefaultAssertionHandler()

SDL_AssertionHandler SDL_GetDefaultAssertionHandler | ( | void |  | ) |

extern

Get the default assertion handler.

This returns the function pointer that is called by default when an assertion is triggered. This is an internal function provided by SDL, that is used for assertions when SDL_SetAssertionHandler() hasn't been used to provide a different function.

Returns
  the default SDL_AssertionHandler that is called when an assert triggers.

Since
  This function is available since SDL 2.0.2.

See also
  SDL_GetAssertionHandler

## SDL_ReportAssertion()

SDL_AssertState SDL_ReportAssertion | ( | SDL_AssertData * | ,
|  | const char * | ,
|  | const char * | ,
|  | int | )

extern

## SDL_ResetAssertionReport()

void SDL_ResetAssertionReport | ( | void |  | ) |

extern

Clear the list of all assertion failures.

This function will clear the list of all assertions triggered up to that point. Immediately following this call, SDL_GetAssertionReport will return no items. In addition, any previously-triggered assertions will be reset to a trigger_count of zero, and their always_ignore state will be false.

Since
  This function is available since SDL 2.0.0.

See also
  SDL_GetAssertionReport

## SDL_SetAssertionHandler()

void SDL_SetAssertionHandler | ( | SDL_AssertionHandler | handler,
|  | void * | userdata )

extern

Set an application-defined assertion handler.

This function allows an application to show its own assertion UI and/or force the response to an assertion failure. If the application doesn't provide this, SDL will try to do the right thing, popping up a system-specific GUI dialog, and probably minimizing any fullscreen windows.

This callback may fire from any thread, but it runs wrapped in a mutex, so it will only fire from one thread at a time.

This callback is NOT reset to SDL's internal handler upon SDL_Quit()!

Parameters

  handler | the SDL_AssertionHandler function to call when an assertion fails or NULL for the default handler.
  userdata | a pointer that is passed to handler.

Since
  This function is available since SDL 2.0.0.

See also
  SDL_GetAssertionHandler