SDL_RunApp(3)
π SDL_RunApp(3) π
okay bestie, we're in the SDL3 FUNCTIONS section of the manual, and today's main character is SDL_RunApp. pull up a chair, grab a boba, this one's actually so useful π«Ά
β¨ NAME β¨
SDL_RunApp β initializes and launches an SDL application, by doing platform-specific initialization before calling your mainFunction and cleanups after it returns, if that is needed for a specific platform, otherwise it just calls mainFunction. literally that simple. it's giving "responsible adult who handles the boring stuff so you don't have to" π
π SYNOPSIS π
#include <SDL3/SDL_main.h>
int SDL_RunApp(int argc, char *argv[], SDL_main_func mainFunction, void *reserved);
yes bestie, that's the whole thing. four params, one int coming back. slay.
π¦ DESCRIPTION π¦
okay so. you can use this if you want to use your own main() implementation without using SDL_main (like when using SDL_MAIN_HANDLED). so if you're out here being a DIY queen with your own entry point, this is your girl. π
and the best part? when you use this, you do not need SDL_SetMainReady(). not me saving you a whole function call, we love a shortcut β¨
also super important: if argv is NULL, SDL will provide command line arguments, either by querying the OS for them if possible, or supplying a filler array if not. so even if your platform is being weird about args, SDL's got you. no cap. π§
π FUNCTION PARAMETERS π
argcβ theargcparameter from the application'smain()function, or0if the platform's main-equivalent has noargc. like, zero, nada, nothing. don't stress it.argvβ theargvparameter from the application'smain()function, orNULLif the platform's main-equivalent has noargv.mainFunctionβ your SDL app's C-stylemain(). NOT the function you're calling this from!! (okay this is the part where everyone gets confused, so let me say it louder for the people in the back π’) its name doesn't matter; it doesn't literally have to bemain. call itgoGirlGofor all SDL cares, the function pointer is what counts. πreservedβ should beNULL(reserved for future use, will probably be platform-specific then). it's the mysterious locked door of parameters. leave it alone. π
π RETURN VALUE π
Returns the return value from mainFunction: 0 on success, otherwise failure; SDL_GetError() might have more information on the failure.
so like, 0 = we ate, anything else = something's wrong and SDL_GetError() is the group chat where the drama gets explained. π
π₯ THREAD SAFETY π₯
Generally this is called once, near startup, from the process's initial thread.
translation: call it one time, at the beginning, from the thread you started with. don't be out here calling it from random threads, that's not the vibe. β
π AVAILABILITY π
This function is available since SDL 3.2.0. so if you're on anything older... bestie, upgrade. π
that's the whole page!! now go write your own main() and let SDL_RunApp do the platform-specific heavy lifting for you. periodt. πβ¨
β cute sign-off from the Simple Directmedia Layer girlies, shipping SDL 3.4.18 ππ¦πΈ
π¦ 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