namespace Brutal.SdlApi;
public static unsafe partial class Sdl
{
public static unsafe partial class Init
{
///
/// Initializes the SDL subsystems selected by .
///
///
/// This is the throwing, ergonomic entry point that replaces the raw SDL_Init binding
/// (which stays available only as because the name
/// Init collides with this enclosing class). The first call into the P/Invoke layer
/// installs the that locates the SDL3 shared
/// library, so no separate registration step is required. Call before the
/// application exits.
///
/// The subsystems to initialize.
/// SDL failed to initialize; the message carries the SDL_GetError text.
public static void Initialize(SdlInitFlags flags)
{
// SDL_Init returns SDL bool (false = failure), rendered as a byte by the raw layer.
if (PInvoke.Init(flags) == 0)
throw SdlException.FromError("SDL_Init failed");
}
///
/// Cleans up all initialized SDL subsystems (SDL_Quit). Safe to call even if
/// was never called.
///
///
/// This hand-written wrapper replaces the generated one so it can tear down the binding's
/// managed state before handing control to native SDL: every registered event watch is
/// removed and its rooting freed, and any parked callback exceptions
/// are discarded. SDL_Quit drops SDL's native watch list wholesale, so skipping this
/// would leak the handles and leave the managed watch map out of sync with native reality —
/// a later re-init and re-registration of the same delegate would silently do nothing.
///
public static void Quit()
{
Events.ClearWatches();
Sdl.ExceptionAggregator.Clear();
PInvoke.Quit();
}
}
}