SDL_AppInit(3)
π SDL_AppInit β the manual page (SDL3 FUNCTIONS, bestie) π
okay so you're in the SDL3 FUNCTIONS section of the manual and you clicked on SDL_AppInit?? slay, this is literally the first thing that happens in your app, it's giving opening night. π
β¨ NAME β¨
SDL_AppInit β the app-implemented initial entry point for SDL_MAIN_USE_CALLBACKS apps. π¬
π SYNOPSIS π
#include <SDL3/SDL_main.h>
SDL_AppResult SDL_AppInit(void **appstate, int argc, char *argv[]);
π¦ DESCRIPTION π¦
So here's the vibe: you implement this function only when you're using SDL_MAIN_USE_CALLBACKS. If you're out here using a standard "main" function, then nope, you should not supply this one. pick a lane bestie π
This function gets called by SDL once, right at startup. It's your moment to initialize whatever needs initializing β possibly create windows, open audio devices, etc. The argc and argv parameters work exactly like they would with a standard "main" function. β¨
π¨ IMPORTANT: this function should not go into an infinite mainloop. do your one-time setup, and then return. that's it. no loitering. π«Ά
The app may optionally assign a pointer to *appstate. That pointer will be handed to you on every future call to the other entry points, so you can preserve application state between functions without needing a global variable. and if you don't set it? then the pointer will be NULL in future entry points. so like... set it, or don't, but know the consequences. π
Now for the return value drama, and this part matters:
- If this function returns
SDL_APP_CONTINUE, the app proceeds to normal operation and will begin receiving repeated calls toSDL_AppIterateandSDL_AppEventfor the life of the program. iconic. this is the "we're so back" path. π₯ - If this function returns
SDL_APP_FAILURE, SDL will callSDL_AppQuitand terminate the process with an exit code that reports an error to the platform. π - If it returns
SDL_APP_SUCCESS, SDL callsSDL_AppQuitand terminates with an exit code that reports success to the platform. π
Also, for the record: this function is called by SDL on the main thread. π§΅
πΈ FUNCTION PARAMETERS πΈ
appstateβ a place where the app can optionally store a pointer for future use. your little state drawer. ποΈargcβ the standard ANSI Cmain'sargc; number of elements inargv.argvβ the standard ANSI Cmain'sargv; array of command line arguments.
β RETURN VALUE β
Returns SDL_APP_FAILURE to terminate with an error, SDL_APP_SUCCESS to terminate with success, SDL_APP_CONTINUE to continue. three doors, pick one. πͺπͺπͺ
π§ THREAD SAFETY π§
This function is called once by SDL, at startup, on a single thread. no threads fighting over it, it's a one-and-done situation. periodt. π
π AVAILABILITY π
This function is available since SDL 3.2.0. so if you're on something older... girl. update. π
π SEE ALSO π
the whole callback friend group, honestly. iykyk. π«Ά
and that's the page!! brought to you by Simple Directmedia Layer, version SDL 3.4.18 β go forth and initialize your windows, bestie, you've got this πβ¨ππ¦πΈ
π¦ where this page comes from
- fedora 43: SDL3-devel 3.4.18-1.fc43 Β· Zlib AND MIT AND Apache-2.0 AND (Apache-2.0 OR MIT)
- fedora 43: SDL3-devel 3.4.18-1.fc43 Β· Zlib AND MIT AND Apache-2.0 AND (Apache-2.0 OR MIT)
- fedora 44: SDL3-devel 3.4.18-1.fc44 Β· Zlib AND MIT AND Apache-2.0 AND (Apache-2.0 OR MIT)
- fedora 44: SDL3-devel 3.4.18-1.fc44 Β· Zlib AND MIT AND Apache-2.0 AND (Apache-2.0 OR MIT)
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash on : a language model's rewrite of the original, under its terms