SDL icon indicating copy to clipboard operation
SDL copied to clipboard

SDL_Quit() causes a segmentation fault.

Open CorruptVoidSoul opened this issue 1 year ago • 6 comments

If SDL_Init() was called outside of the main function, then SDL_Quit won't work properly.

CorruptVoidSoul avatar Feb 15 '24 11:02 CorruptVoidSoul

Can you provide a simple example so we can see what’s happening?

slouken avatar Feb 15 '24 15:02 slouken

Ok so let's say I have an initialisation function that I call at the beginning of the program with the call to SDL_Init in it. When said program ends, calling SDL_Quit, be it at the end of the main, with an atexit or with a custom exit function will cause a segmentation fault. The temporary fix was to call both SDL_Init() and SDL_Quit() in the main function.

CorruptVoidSoul avatar Feb 15 '24 18:02 CorruptVoidSoul

@CorruptVoidSoul I'm using SDL_Init & SDL_Quit outside main successfully on Android & Windows using SDL3. Can you reproduce the crash using a minimal example? Which platform and which version of SDL are you using?

AntTheAlchemist avatar Feb 15 '24 18:02 AntTheAlchemist

Running SDL 2.30.0 on Termux (Android) and compiling with Clang or MinGW depending on the target. I didn't feel like updating to SDL3 because going from 1.14 to 2 was a titanic task for a beginner like me, so if I have to redo the same for SDL3 i'm not gonna feel good. Maybe SDL3 has this issue fixed. Also it isn't available on the Termux repos. I guess I could only use it for cross-compiling.

CorruptVoidSoul avatar Feb 15 '24 21:02 CorruptVoidSoul

SDL3 is still evolving and would be another titanic task to migrate to, as you said. SDL2 should work, it was working when I last used it. Might be something that happened during your SDL1 to SDL2 migration? Can you test your build on a desktop? Can you create a minimal Android build to reproduce it?

AntTheAlchemist avatar Feb 15 '24 23:02 AntTheAlchemist

I did the migration for another project, the one I discovered the bug on was made with SDL2 since the beginning. However Windows does not warn me about the seg fault.

CorruptVoidSoul avatar Feb 16 '24 09:02 CorruptVoidSoul