SDL_assert.h File Reference
`#include "SDL_config.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() raise(SIGTRAP)
#define | SDL_FUNCTION "???"
#define | SDL_FILE __FILE__
#define | SDL_LINE __LINE__
#define | SDL_NULL_WHILE_LOOP_CONDITION (0)
#define | SDL_disabled_assert(condition) do { (void) sizeof ((condition)); } while (SDL_NULL_WHILE_LOOP_CONDITION)
#define | SDL_enabled_assert(condition)
#define | SDL_assert(condition) SDL_disabled_assert(condition)
#define | SDL_assert_release(condition) SDL_enabled_assert(condition)
#define | SDL_assert_paranoid(condition) SDL_disabled_assert(condition)
#define | SDL_assert_always(condition) SDL_enabled_assert(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)
| Set an application-defined assertion handler. More...
SDL_AssertionHandler | SDL_GetDefaultAssertionHandler (void)
| Get the default assertion handler. More...
SDL_AssertionHandler | SDL_GetAssertionHandler (void **puserdata)
| Get the current assertion handler. More...
const SDL_AssertData * | SDL_GetAssertionReport (void)
| Get a list of all assertion failures. More...
void | SDL_ResetAssertionReport (void)
| Reset the list of all assertion failures. More...

## Macro Definition Documentation

## SDL_assert

#define SDL_assert | ( |  | condition | ) | SDL_disabled_assert(condition)

Definition at line 169 of file SDL_assert.h.

Referenced by add_audio_device(), add_capture_device(), AllocateDataQueuePacket(), close_audio_device(), ConvertRGBtoPacked4(), ConvertRGBtoPlanar2x2(), DequeueEvent_LockFree(), EnqueueEvent_LockFree(), EnsureStreamBufferSize(), main(), mark_device_removed(), open_audio_device(), RunEpicTest(), SDL_AddEvent(), SDL_AudioDetectDevices_Default(), SDL_AudioStreamFlush(), SDL_AudioStreamPut(), SDL_AudioStreamPutInternal(), SDL_BufferQueueDrainCallback(), SDL_BufferQueueFillCallback(), SDL_BuildAudioTypeCVTFromFloat(), SDL_BuildAudioTypeCVTToFloat(), SDL_CaptureAudio(), SDL_ChooseAudioConverters(), SDL_Convert51To71(), SDL_Convert51ToQuad(), SDL_Convert51ToStereo(), SDL_Convert71To51(), SDL_Convert_Byteswap(), SDL_Convert_F32_to_S32_Scalar(), SDL_ConvertMonoToStereo(), SDL_ConvertQuadTo51(), SDL_ConvertQuadToStereo(), SDL_ConvertStereoTo51(), SDL_ConvertStereoToMono(), SDL_ConvertStereoToQuad(), SDL_CutEvent(), SDL_DestroyRenderer(), SDL_DetachThread(), SDL_GetAudioDeviceName(), SDL_GetGrabbedWindow(), SDL_GetMouseFocus(), SDL_GetRendererOutputSize(), SDL_GetWindowGrab(), SDL_HapticQuit(), SDL_HapticRumblePlay(), SDL_IntersectRectAndLine(), SDL_IOReady(), SDL_JoystickQuit(), SDL_LoadBMP_RW(), SDL_OpenAudio(), SDL_OpenedAudioDeviceDisconnected(), SDL_PeekIntoDataQueue(), SDL_PrivateShouldInitSubsystem(), SDL_PrivateSubsystemRefCountIncr(), SDL_ReadFromDataQueue(), SDL_ResampleAudioStream(), SDL_ResampleCVT(), SDL_RunAudio(), SDL_SendPendingQuit(), SDL_SetKeyboardFocus(), SDL_SetWindowGammaRamp(), SDL_SW_CreateYUVTexture(), SDL_SYS_SetupThread(), SDL_TouchQuit(), SDL_TraverseShapeTree(), SDL_UpdateYUVTexture(), SDL_WriteToDataQueue(), SDLTest_Assert(), SDLTest_TrackedFree(), SDLTest_TrackedRealloc(), surface_testCompleteSurfaceConversion(), TestAssertions(), WatchJoystick(), and WINRT_SetDisplayOrientationsPreference().

## SDL_assert_always

#define SDL_assert_always | ( |  | condition | ) | SDL_enabled_assert(condition)

Definition at line 185 of file SDL_assert.h.

## SDL_assert_data

#define SDL_assert_data SDL_AssertData

Definition at line 280 of file SDL_assert.h.

Referenced by SDL_GenerateAssertionReport(), and SDL_ResetAssertionReport().

## 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 | ) | SDL_disabled_assert(condition)

Definition at line 171 of file SDL_assert.h.

Referenced by TestAssertions().

## SDL_assert_release

#define SDL_assert_release | ( |  | condition | ) | SDL_enabled_assert(condition)

Definition at line 170 of file SDL_assert.h.

Referenced by TestAssertions().

## SDL_assert_state

#define SDL_assert_state SDL_AssertState

Definition at line 279 of file SDL_assert.h.

Referenced by SDL_AbortAssertion(), SDL_PromptAssertion(), and SDL_ReportAssertion().

## SDL_disabled_assert

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

Definition at line 99 of file SDL_assert.h.

## SDL_enabled_assert

#define SDL_enabled_assert | ( |  | condition | ) |

Value:
do { \
while ( !(condition) ) { \
static struct SDL_AssertData sdl_assert_data = { \
0, 0, #condition, 0, 0, 0, 0 \
}; \
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_LINE
#define SDL_LINE
Definition: SDL_assert.h:74
SDL_FILE
#define SDL_FILE
Definition: SDL_assert.h:73
SDL_AssertState
SDL_AssertState
Definition: SDL_assert.h:102
SDL_FUNCTION
#define SDL_FUNCTION
Definition: SDL_assert.h:71
SDL_ReportAssertion
SDL_AssertState SDL_ReportAssertion(SDL_AssertData *, const char *, const char *, int)
SDL_NULL_WHILE_LOOP_CONDITION
#define SDL_NULL_WHILE_LOOP_CONDITION
Definition: SDL_assert.h:96
SDL_ASSERTION_RETRY
Definition: SDL_assert.h:104
condition
GLenum condition
Definition: SDL_opengl_glext.h:8670
SDL_AssertData
Definition: SDL_assert.h:111
SDL_ASSERTION_BREAK
Definition: SDL_assert.h:105

Definition at line 145 of file SDL_assert.h.

## SDL_FILE

#define SDL_FILE __FILE__

Definition at line 73 of file SDL_assert.h.

## SDL_FUNCTION

#define SDL_FUNCTION "???"

Definition at line 71 of file SDL_assert.h.

## SDL_LINE

#define SDL_LINE __LINE__

Definition at line 74 of file SDL_assert.h.

## SDL_NULL_WHILE_LOOP_CONDITION

#define SDL_NULL_WHILE_LOOP_CONDITION (0)

Definition at line 96 of file SDL_assert.h.

## SDL_TriggerBreakpoint

#define SDL_TriggerBreakpoint | ( |  | ) | raise(SIGTRAP)

Definition at line 60 of file SDL_assert.h.

## Typedef Documentation

## SDL_AssertionHandler

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

Definition at line 188 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 102 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
Definition: SDL_assert.h:106
SDL_AssertState
SDL_AssertState
Definition: SDL_assert.h:102
SDL_ASSERTION_RETRY
Definition: SDL_assert.h:104
SDL_ASSERTION_ALWAYS_IGNORE
Definition: SDL_assert.h:108
SDL_ASSERTION_IGNORE
Definition: SDL_assert.h:107
SDL_ASSERTION_BREAK
Definition: SDL_assert.h:105

## Function Documentation

## SDL_GetAssertionHandler()

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

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().

Parameters

  puserdata | 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.

Returns
  The SDL_AssertionHandler that is called when an assert triggers.

Definition at line 433 of file SDL_assert.c.

References assertion_handler, assertion_userdata, and NULL.

{
if (userdata != NULL) {
*userdata = assertion_userdata;
}
return assertion_handler;
}
assertion_handler
static SDL_AssertionHandler assertion_handler
Definition: SDL_assert.c:65
assertion_userdata
static void * assertion_userdata
Definition: SDL_assert.c:66
NULL
#define NULL
Definition: begin_code.h:164

## SDL_GetAssertionReport()

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

Get a list of all assertion failures.

Get all assertions triggered since 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; }`

Returns
  List of all assertions.

See also
  SDL_ResetAssertionReport

Definition at line 409 of file SDL_assert.c.

References triggered_assertions.

{
return triggered_assertions;
}
triggered_assertions
static SDL_assert_data * triggered_assertions
Definition: SDL_assert.c:59

## SDL_GetDefaultAssertionHandler()

SDL_AssertionHandler SDL_GetDefaultAssertionHandler | ( | void |  | ) |

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.

Definition at line 428 of file SDL_assert.c.

References SDL_PromptAssertion().

{
return SDL_PromptAssertion;
}
SDL_PromptAssertion
static SDL_assert_state SDL_PromptAssertion(const SDL_assert_data *data, void *userdata)
Definition: SDL_assert.c:145

## SDL_ReportAssertion()

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

## SDL_ResetAssertionReport()

void SDL_ResetAssertionReport | ( | void |  | ) |

Reset the list of all assertion failures.

Reset list of all assertions triggered.

See also
  SDL_GetAssertionReport

Definition at line 414 of file SDL_assert.c.

References NULL, SDL_assert_data, SDL_FALSE, and triggered_assertions.

Referenced by SDL_GenerateAssertionReport().

{
SDL_assert_data *next = NULL;
SDL_assert_data *item;
for (item = triggered_assertions; item != NULL; item = next) {
next = (SDL_assert_data *) item->next;
item->always_ignore = SDL_FALSE;
item->trigger_count = 0;
item->next = NULL;
}
triggered_assertions = NULL;
}
SDL_AssertData::next
const struct SDL_AssertData * next
Definition: SDL_assert.h:119
triggered_assertions
static SDL_assert_data * triggered_assertions
Definition: SDL_assert.c:59
SDL_FALSE
Definition: SDL_stdinc.h:141
NULL
#define NULL
Definition: begin_code.h:164
SDL_assert_data
#define SDL_assert_data
Definition: SDL_assert.h:280

## SDL_SetAssertionHandler()

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

Set an application-defined assertion handler.

This allows an app to show its own assertion UI and/or force the response to an assertion failure. If the app 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.

Setting the callback to NULL restores SDL's original internal handler.

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

Return SDL_AssertState value of how to handle the assertion failure.

Parameters

  handler | Callback function, called when an assertion fails.
  userdata | A pointer passed to the callback as-is.

Definition at line 398 of file SDL_assert.c.

References assertion_handler, assertion_userdata, NULL, and SDL_PromptAssertion().

{
if (handler != NULL) {
assertion_handler = handler;
assertion_userdata = userdata;
} else {
assertion_handler = SDL_PromptAssertion;
assertion_userdata = NULL;
}
}
assertion_handler
static SDL_AssertionHandler assertion_handler
Definition: SDL_assert.c:65
assertion_userdata
static void * assertion_userdata
Definition: SDL_assert.c:66
SDL_PromptAssertion
static SDL_assert_state SDL_PromptAssertion(const SDL_assert_data *data, void *userdata)
Definition: SDL_assert.c:145
NULL
#define NULL
Definition: begin_code.h:164