<?xml version="1.0"?>
<rss version="2.0">
	<channel>
		<title>[A5]: Crash when destroying samples before shutdown</title>
		<link>http://www.allegro.cc/forums/view/611067</link>
		<description>Allegro.cc Forum Thread</description>
		<webMaster>matthew@allegro.cc (Matthew Leverton)</webMaster>
		<lastBuildDate>Tue, 18 Sep 2012 15:35:39 +0000</lastBuildDate>
	</channel>
	<item>
		<description><![CDATA[<div class="mockup v2"><p>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).</p><p>Why and when does al_destroy_sample() crash? Could it be that the sample&#39;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.</p><p>Anyone?</p><p>EDIT: Stupied mistake of trying to free same memory twice. Feel free to remove this thread.
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (TeaRDoWN)</author>
		<pubDate>Mon, 17 Sep 2012 14:39:32 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><p>If you&#39;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)</p><p>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.
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (Audric)</author>
		<pubDate>Mon, 17 Sep 2012 14:54:53 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><p>Have you made sure that Allegro was deinitialized <i>after</i> you destroyed everything? I&#39;ve encountered this problem by putting the shutdown code in an <span class="source-code"><a href="http://www.delorie.com/djgpp/doc/libc/libc_52.html" target="_blank">atexit</a></span> callback but letting Allegro register a custom <span class="source-code"><a href="http://www.delorie.com/djgpp/doc/libc/libc_52.html" target="_blank">atexit</a></span> callback. In such a situation, Allegro&#39;s <span class="source-code"><a href="http://www.delorie.com/djgpp/doc/libc/libc_52.html" target="_blank">atexit</a></span> callback may be run first, so instead of <span class="source-code"><a href="http://www.allegro.cc/manual/al_init"><span class="a">al_init</span></a><span class="k2">(</span><span class="k2">)</span></span> you have to use <span class="source-code"><a href="http://www.allegro.cc/manual/al_install_system"><span class="a">al_install_system</span></a><span class="k2">(</span>NULL, ALLEGRO_VERSION_INT<span class="k2">)</span></span> and call <span class="source-code"><a href="http://www.allegro.cc/manual/al_uninstall_system"><span class="a">al_uninstall_system</span></a><span class="k2">(</span><span class="k2">)</span></span> in your custom <span class="source-code"><a href="http://www.delorie.com/djgpp/doc/libc/libc_52.html" target="_blank">atexit</a></span> callback.
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (Luiji99)</author>
		<pubDate>Tue, 18 Sep 2012 01:40:49 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><p>If you&#39;re still unsure whether those are deleted only once or twice, you could try running it trough valgrind.
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (J-Gamer)</author>
		<pubDate>Tue, 18 Sep 2012 15:35:39 +0000</pubDate>
	</item>
</rss>
