<?xml version="1.0"?>
<rss version="2.0">
	<channel>
		<title>Unloading datafile causes program to crash.</title>
		<link>http://www.allegro.cc/forums/view/589573</link>
		<description>Allegro.cc Forum Thread</description>
		<webMaster>matthew@allegro.cc (Matthew Leverton)</webMaster>
		<lastBuildDate>Tue, 16 Jan 2007 01:58:48 +0000</lastBuildDate>
	</channel>
	<item>
		<description><![CDATA[<div class="mockup v2"><p>Ok so here&#39;s basically the code:</p><p>     allegro_message(&quot;Sounds destroyed!&quot;);                         //debug<br />     unload_datafile(data);<br />     allegro_message(&quot;Datafile unloaded!&quot;);                        //debug<br />     remove_sound();<br />     allegro_message(&quot;Datafile unloaded and sound removed!&quot;);     //debug<br />     allegro_exit();<br />}<br />END_OF_MAIN();</p><p>The sounds destroyed message comes up and then BOOM! The program crashes! This is pretty strange and I cannot seem to think of what the reason may be. Before the destruction of the sounds, I also free up and destroy bitmaps. All the bitmaps and sounds, etc., come from the datafile and I was thinking that that may possibly be the problem but I see no reason for that to be so...does the call to unload_datafile() do something I&#39;m not aware of other than freeing up all the objects in the datafile and removing it from memory??
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (XcronZ3X)</author>
		<pubDate>Mon, 15 Jan 2007 08:00:21 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><p>You&#39;re freeing the stuff twice. unload_datafile will unload all the objects. Don&#39;t manually unload the individual elements beforehand.
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (Matthew Leverton)</author>
		<pubDate>Mon, 15 Jan 2007 08:01:45 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><p>Mmmm, so it was as I thought...but it feels strange that unload_datafile would even take care of all of the memory that I used when taking objects from the datafile and putting them into objects that I create while the program is running..</p><p>It also feels weird that by freeing the objects I create while the program is running go all the way to the root objects from the datafile and free them up as well..
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (XcronZ3X)</author>
		<pubDate>Mon, 15 Jan 2007 08:16:54 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><p>This is broken:
</p><div class="source-code snippet"><div class="inner"><pre>DATA <span class="k3">*</span>dat <span class="k3">=</span> <a href="http://www.allegro.cc/manual/load_datafile" target="_blank"><span class="a">load_datafile</span></a><span class="k2">(</span><span class="s">"foo.dat"</span><span class="k2">)</span><span class="k2">;</span>
<a href="http://www.allegro.cc/manual/BITMAP" target="_blank"><span class="a">BITMAP</span></a> <span class="k3">*</span>bmp <span class="k3">=</span> dat<span class="k2">[</span>foo<span class="k2">]</span>.dat<span class="k2">;</span>
<a href="http://www.allegro.cc/manual/destroy_bitmap" target="_blank"><span class="a">destroy_bitmap</span></a><span class="k2">(</span>bmp<span class="k2">)</span><span class="k2">;</span>
<a href="http://www.allegro.cc/manual/unload_datafile" target="_blank"><span class="a">unload_datafile</span></a><span class="k2">(</span>dat<span class="k2">)</span><span class="k2">;</span>
</pre></div></div><p>
But if you are blitting the object to another bitmap you create, then you must unload both. It&#39;s simple to remember. If you use create/load_bitmap, then you need to destroy it.
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (Matthew Leverton)</author>
		<pubDate>Mon, 15 Jan 2007 08:34:16 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><p>Remember, XcronZ3X - A pointer (BITMAP *bmp) just &quot;points&quot; to a chunk of data, in this case a bitmap. When you do <span class="source-code"><a href="http://www.allegro.cc/manual/BITMAP" target="_blank"><span class="a">BITMAP</span></a> <span class="k3">*</span>bmp <span class="k3">=</span> dat<span class="k2">[</span>foo<span class="k2">]</span>.dat<span class="k2">;</span></span> you copy the <i>pointer</i> to the bitmap data - not the actual bitmap data.
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (Jonatan Hedborg)</author>
		<pubDate>Mon, 15 Jan 2007 12:36:19 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><p>In other words, treat each datafile in only one of the following ways.<br />a) Use load_datafile() to load all of its content into memory, use it, finally use unload_datafile() to free the loaded content. Do not free() or destroy_XXXX() anything from the datafile manually.<br />b) Load objects one by one using load_datafile_object(); unload using unload_datafile_object(). The same caveats as for a) hold true.<br />c) Treat the datafile as a directory, and load objects using the #-syntax provided by the normal loading functions (e.g. load_bitmap(&quot;my_datafile#sprite.bmp&quot;); ). Objects loaded this way can and should be freed using the appropriate destroy_XXXX() routines.</p><p>Whatever you do, don&#39;t mix the above unless you know exactly what you&#39;re doing.
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (Tobias Dammers)</author>
		<pubDate>Tue, 16 Jan 2007 01:58:48 +0000</pubDate>
	</item>
</rss>
