SDL_AppIterate(3)
π SDL_AppIterate(3) β the SDL3 FUNCTIONS girlies' edition π
okay so bestie, this is SDL_AppIterate(3), and it's literally the heartbeat of your SDL3 app. no cap.
β¨ NAME β¨
SDL_AppIterate β the app-implemented iteration entry point for SDL_MAIN_USE_CALLBACKS apps. it's giving "main loop, but make it a callback." π¦
β¨ SYNOPSIS β¨
#include <SDL3/SDL_main.h>
SDL_AppResult SDL_AppIterate(void *appstate);
β¨ DESCRIPTION β¨
so here's the vibe: you implement this function when you're using SDL_MAIN_USE_CALLBACKS. if you're doing a standard "main" function instead? then bestie, do not supply this. not the moment. π
this function gets called repeatedly by SDL after SDL_AppInit returns SDL_APP_CONTINUE. it should act as a single iteration of your program's primary loop β like, it should update whatever state it needs to update and draw a new frame of video, usually. one lap around the track, then dip. πβοΈ
on some platforms, this function will be called at the refresh rate of the display β and plot twist, that rate might literally change during the life of your app! there are no promises made about what frequency this function might run at. so if you need to know how much time has passed since the last iteration, you should use SDL's timer functions. don't guess, bestie. β°
good news tho: there is no need to process the SDL event queue during this function. SDL will send events as they arrive in SDL_AppEvent, and in most cases the event queue will be empty when this function runs anyhow. so you can just vibe. π
β οΈ real talk: this function should not go into an infinite mainloop. it should do one iteration of whatever the program does and return. no holding the group chat hostage. periodt.
the appstate parameter is an optional pointer provided by the app during SDL_AppInit(). if the app never provided a pointer, this will be NULL. π€·βοΈ
now for the return value drama, because this is where your app's whole fate lives:
- if this function returns
SDL_APP_CONTINUE, the app continues normal operation, receiving repeated calls toSDL_AppIterateandSDL_AppEventfor the life of the program. iconic, thriving, slaying. π - 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. π
and one more thing: this function is called by SDL on the main thread. main character energy, main thread. obviously. π
β¨ FUNCTION PARAMETERS β¨
appstateβ an optional pointer, provided by the app inSDL_AppInit. π«Ά
β¨ RETURN VALUE β¨
returns SDL_APP_FAILURE to terminate with an error, SDL_APP_SUCCESS to terminate with success, SDL_APP_CONTINUE to continue. pick your fighter. π₯
β¨ THREAD SAFETY β¨
this function may get called concurrently with SDL_AppEvent() for events not pushed on the main thread. so like... be aware. sharing is caring but also sometimes sharing is a data race. π
β¨ AVAILABILITY β¨
this function is available since SDL 3.2.0. not me being a relatively recent addition and still eating every single time. β
β¨ SEE ALSO β¨
and that's the whole page, bestie!! brought to you by Simple Directmedia Layer, running SDL 3.4.18, mwah π go forth and iterate, one frame at a time β¨π¦π
π¦ 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