SDL_assert_always(3)

πŸ’– SDL_assert_always β€” the assert that NEVER takes a day off πŸ’–

okay bestie, welcome to the SDL_assert_always page from the SDL3 functions manual 🌸 yes it's a 3 page, yes it's a macro, yes we're gonna get into it.


✨ NAME ✨

SDL_assert_always β€” an assertion test that is always performed. no days off. no skipping. she's committed. πŸ’…


πŸŽ€ SYNOPSIS πŸŽ€

#include <SDL3/SDL_assert.h>

#define SDL_assert_always(condition) SDL_enabled_assert(condition)

literally the whole thing. a macro that hands off to SDL_enabled_assert. that's it, that's the girl πŸ¦‹


πŸ’œ DESCRIPTION πŸ’œ

so here's the tea β˜• this macro is always enabled, no matter what SDL_ASSERT_LEVEL is set to. like, you cannot turn her off. she shows up to every party, invited or not.

🚨 and that is exactly why you almost never want to use this. bestie. listen. this can trigger on an end-user's system and crash your program. not your dev machine, not your test rig β€” a real person's real computer. ngl that's giving main character energy in the worst way possible 😭

okay but here's a thing you can do: you can set the environment variable "SDL_ASSERT" to one of several strings β€” "abort", "break", "retry", "ignore", "always_ignore" β€” to force a default behavior. which honestly can be super desirable for automation purposes πŸ€–

and here's a specific little scenario that's lowkey iconic: if your platform requires GUI interfaces to happen on the main thread, but you're debugging an assertion in a background thread, it might be desirable to set this to "break" so that your debugger takes control as soon as the assert is triggered β€” instead of risking a bad UI interaction (deadlock, etc.) in the application. deadlocks are NOT the vibe πŸ™ˆ


🫢 MACRO PARAMETERS 🫢

  • condition β€” boolean value to test. that's the whole parameter. that's her. ✨

🌈 THREAD SAFETY 🌈

it is safe to call this macro from any thread. any of them. all of them. go off, queen πŸ‘‘


⭐ AVAILABILITY ⭐

this macro has been available since SDL 3.2.0. vintage-ish but make it fresh πŸ’…


okay that's the page!! source is Simple Directmedia Layer, version SDL 3.4.18, and we're flipping through it in the SDL 3 era, dated with all the love of a SDL_assert_always(3) footer πŸŽ€ remember: assert responsibly, don't crash your users' computers, and set "SDL_ASSERT" to "break" when you're debugging off the main thread. mwah πŸ’–βœ¨

πŸ“¦ where this page comes from