namespace Brutal.SdlApi.Mixer;
public static unsafe partial class SdlMixer
{
///
/// Shuts down SDL_mixer, releasing all mixers, tracks, audio and decoders it still owns.
///
///
/// Hand-written (rather than generated) so it also tears down this binding's managed callback
/// state: it frees the s rooting any
/// registered callback delegates and discards any parked callback exceptions (they refer to a
/// session that is ending, so they are cleared rather than rethrown). Mirrors core's
/// Sdl.Init.Quit teardown. Calling a mixer/track/group ergonomic method after this and
/// before a fresh MIX_Init is undefined, exactly as in native SDL_mixer.
///
public static void Quit()
{
// Order is a memory-safety contract. MIX_Quit stops all audio output, closes the audio devices,
// and destroys every mixer/track/group (see its header docs), so ONLY after it returns is the
// audio device thread guaranteed to have stopped and no trampoline can fire again. The callback
// GCHandles are the userdata those trampolines dereference, so they must be freed strictly AFTER
// MIX_Quit — freeing them first (the previous order) left a window in which the still-running
// audio thread could resolve a freed handle (undefined behaviour). Parked callback exceptions
// refer to the session that is ending, so they are discarded (not rethrown) once no more can be
// pushed.
PInvoke.Quit();
ClearCallbacks();
ExceptionAggregator.Clear();
}
}