Allegro.cc - Online Community

Allegro.cc Forums » Programming Questions » [A5]: Crash when destroying samples before shutdown

This thread is locked; no one can reply to it. rss feed Print
[A5]: Crash when destroying samples before shutdown
TeaRDoWN
Member #8,518
April 2007
avatar

When shutting down my game I unload all loaded assets. When I come to the samples I first run al_stop_samples(). The samples are stored in an array and I step through it and call al_destroy_sample() on each sample. When I start getting to the end (246 out of 255) the process crash, 100% repro. If I skip loading that sample that crash the game it will instead crash on the next sample (247).

Why and when does al_destroy_sample() crash? Could it be that the sample's memory slot have been corrupted by other data? When debugging it is really hard to see anything since all I see in the debugger for Sound[246] is its memory address and that does not change from when it is loaded to when I try to destroy it.

Anyone?

EDIT: Stupied mistake of trying to free same memory twice. Feel free to remove this thread.

Audric
Member #907
January 2001

If you've mistakenly freed the same piece of memory twice, you can later get a crash in any of the memory allocation functions (malloc, free, etc)

To see if this is your problem, you can modify your program to set to NULL everything you free, right after the call to al_destroy_sample(), free(), al_destroy_bitmap() etc.

Luiji99
Member #12,254
September 2010

Have you made sure that Allegro was deinitialized after you destroyed everything? I've encountered this problem by putting the shutdown code in an atexit callback but letting Allegro register a custom atexit callback. In such a situation, Allegro's atexit callback may be run first, so instead of al_init() you have to use al_install_system(NULL, ALLEGRO_VERSION_INT) and call al_uninstall_system() in your custom atexit callback.

Programming should be fun. That's why I hate Java.

J-Gamer
Member #12,491
January 2011
avatar

If you're still unsure whether those are deleted only once or twice, you could try running it trough valgrind.

" There are plenty of wonderful ideas in The Bible, but God isn't one of them." - Derezo
"If your body was a business, thought would be like micro-management and emotions would be like macro-management. If you primarily live your life with emotions, then you are prone to error on the details. If you over-think things all the time you tend to lose scope of priorities." - Mark Oates

Go to: