Understanding SQL_Quit()

Hi everyone,

I’m trying to better understand SDL_Quit(). I’m creating a small Swift API to wrap SDL (for educational purposes) and am thinking about how to properly handle different types of errors.

In particular, I’m wondering if I should call SDL_Quit() when the application terminates prematurely as a result of an unrecoverable error?

The operating system will clean up everything when the application exits anyway, so it’s not strictly necessary for a situation where the application is just going to display an error message and then bail out.

1 Like

So it’s really needed when the application should continue doing other (non SDL) things?

But I assume it’s good practice to call SDL_Quit anyway, before quitting the application?

But I assume it’s good practice to call SDL_Quit anyway, before quitting the application?

Yes, though I wouldn’t call it in case of a crash (might not even be safe to call it from a signal handler).

Especially if you quit the application in a normal way, it’ll make sure that all resources are cleanly released and memory is freed - while technically that doesn’t matter as the OS should do that anyway (hopefully…), this is helpful for tools that detect memory-leaks (like ASan or valgrind), so they don’t report stuff in SDL that would’ve been freed by SDL_Quit()