I was experiencing some random crashes when uninstalling Allegro.
I found out that if I have a function called shutdown(), al_uninstall_system will execute it twice when called.
I'm compiling with GCC on Linux. Compiling with G++ does not reproduce the error.
Allegro v5.2.4.1
GCC v4.8.4
Linux v3.13.0-37
If I rename the function, no error or warnings are emitted.
The code below runs fine, but shutdown() is called twice when Allegro is uninstalled.
Output:
al_uninstall_system() start Calling shutdown() Calling shutdown() al_uninstall_system() end
Am I blind, but when do you call "void shutdown()"?
I see you're program prints "Calling shutdown()", but it was never called.
Just put a breakpoint on shutdown() to see where it is being called from?
As you probably know you would normally just call al_init, not al_install_system or al_uninstall_system.
It's a linking bug. Allegro sees your shutdown function and calls it mistakenly, thinking it is its own version of shutdown.
You can debug this easily by setting a breakpoint in your shutdown function. Then when allegro calls it, gdb will stop and let you get a backtrace. Do it twice. Post the results.
Backtrace:
#0 shutdown () at test.c:28 #1 0x00007ffff5de0786 in xcb_disconnect () from /usr/lib/x86_64-linux-gnu/libxcb.so.1 #2 0x00007ffff6caf4e7 in XCloseDisplay () from /usr/lib/x86_64-linux-gnu/libX11.so.6 #3 0x00007ffff7b77a17 in ?? () from /usr/lib/x86_64-linux-gnu/liballegro.so.5.2 #4 0x00007ffff7b2bcd5 in ?? () from /usr/lib/x86_64-linux-gnu/liballegro.so.5.2 #5 0x00007ffff7b1fd4d in _al_run_exit_funcs () from /usr/lib/x86_64-linux-gnu/liballegro.so.5.2 #6 0x00007ffff7b2bdb5 in al_uninstall_system () from /usr/lib/x86_64-linux-gnu/liballegro.so.5.2 #7 0x0000000000400c89 in real_shutdown () at test.c:35 #8 0x0000000000400da5 in main (argc=1, argv=0x7fffffffe158) at test.c:49
It's a linking bug. Allegro sees your shutdown function and calls it mistakenly, thinking it is its own version of shutdown.
Apparently, yes. I just found out shutdown() is POSIX function(https://linux.die.net/man/2/shutdown), so I better not have another function with the same name.
Thank you!