<?xml version="1.0"?>
<rss version="2.0">
	<channel>
		<title>Loading stuff from datafile question</title>
		<link>http://www.allegro.cc/forums/view/593585</link>
		<description>Allegro.cc Forum Thread</description>
		<webMaster>matthew@allegro.cc (Matthew Leverton)</webMaster>
		<lastBuildDate>Sun, 14 Oct 2007 01:00:33 +0000</lastBuildDate>
	</channel>
	<item>
		<description><![CDATA[<div class="mockup v2"><p>Hi.  I would like to load something from a datafile.  I can get it work with the codes below:</p><div class="source-code snippet"><div class="inner"><pre><a href="http://www.allegro.cc/manual/BITMAP" target="_blank"><span class="a">BITMAP</span></a> <span class="k3">*</span>bmp<span class="k2">;</span>
<a href="http://www.allegro.cc/manual/DATAFILE" target="_blank"><span class="a">DATAFILE</span></a> <span class="k3">*</span>dat<span class="k2">;</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">"myfile.dat"</span><span class="k2">)</span><span class="k2">;</span>
bmp <span class="k3">=</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><span class="k2">)</span>dat<span class="k2">[</span>COOL_PICTURE<span class="k2">]</span>.dat<span class="k2">;</span>
</pre></div></div><p>

However, is it possible to make the &#39;COOL_PICTURE portion to be dynamic?<br />Such as:</p><div class="source-code snippet"><div class="inner"><pre>string pictureName <span class="k3">=</span> <span class="s">"COOL_PICTURE"</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="k2">;</span>
<a href="http://www.allegro.cc/manual/DATAFILE" target="_blank"><span class="a">DATAFILE</span></a> <span class="k3">*</span>dat<span class="k2">;</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">"myfile.dat"</span><span class="k2">)</span><span class="k2">;</span>
bmp <span class="k3">=</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><span class="k2">)</span>dat<span class="k2">[</span>pictureName<span class="k2">]</span>.dat<span class="k2">;</span>
</pre></div></div><p>

Which of course did not work.  I&#39;m just asking is there a way so I can get input and load the stuff I call for?
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (The_Wind)</author>
		<pubDate>Thu, 11 Oct 2007 10:42:24 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><p>pictureName needs to be an int, not a string. Basically, when you refer to an item in a datafile you are just pointing to a member of an array. You could do this:
</p><div class="source-code snippet"><div class="inner"><pre><span class="p">#define COOL_PICTURE 1</span>
<span class="c">//be careful not to access beyond the limits of the datafile array!</span>
<span class="k1">int</span> myPictureName <span class="k3">=</span> COOL_PICTURE<span class="k2">;</span>
</pre></div></div><p>
Provided that the picture you are referring is in the given place in your datafile. You can look at the header file produced by grabber to find out where the bitmap is in the datafile and use that <i>integer</i> to reference the items in the datafile.
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (Edward Sheets)</author>
		<pubDate>Thu, 11 Oct 2007 10:59:44 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><p>For animations and stuff I used to put in dummy markers in the datafile and use an offset from that to get the current sprite.
</p><div class="source-code snippet"><div class="inner"><pre><span class="k1">int</span> offset <span class="k3">=</span> <span class="n">1</span><span class="k2">;</span>
<span class="k1">int</span> start <span class="k3">=</span> EXPLODE_MARKER<span class="k2">;</span>
<span class="k1">while</span> <span class="k2">(</span> offset <span class="k3">=</span> <span class="n">1</span><span class="k2">;</span> offset <span class="k3">&lt;</span> <span class="n">10</span><span class="k2">;</span> offset<span class="k3">+</span><span class="k3">+</span> <span class="k2">)</span><span class="k2">{</span>
   <a href="http://www.allegro.cc/manual/draw_sprite" target="_blank"><span class="a">draw_sprite</span></a><span class="k2">(</span> buffer, datafile<span class="k2">[</span> start <span class="k3">+</span> offset <span class="k2">]</span>, ... <span class="k2">)</span><span class="k2">;</span>
<span class="k2">}</span>
</pre></div></div><p>
So you can loop over sprites easily.
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (kazzmir)</author>
		<pubDate>Thu, 11 Oct 2007 11:07:18 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><div class="quote_container"><div class="title">Quote:</div><div class="quote"><p>
However, is it possible to make the &#39;COOL_PICTURE portion to be dynamic?
</p></div></div><p>
Yes.  I am with you, this is much nicer then all this &#39;locate by index&#39; stuff from the 80s.</p><div class="source-code snippet"><div class="inner"><pre>string pictureName <span class="k3">=</span> <span class="s">"COOL_PICTURE"</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="k2">;</span>
<a href="http://www.allegro.cc/manual/DATAFILE" target="_blank"><span class="a">DATAFILE</span></a> <span class="k3">*</span>dat<span class="k2">;</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">"myfile.dat"</span><span class="k2">)</span><span class="k2">;</span>
bmp <span class="k3">=</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><span class="k2">)</span><a href="http://www.allegro.cc/manual/find_datafile_object" target="_blank"><span class="a">find_datafile_object</span></a><span class="k2">(</span>dat, pictureName.c_str<span class="k2">(</span><span class="k2">)</span><span class="k2">)</span>.dat<span class="k2">;</span>
</pre></div></div><p>
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (ImLeftFooted)</author>
		<pubDate>Thu, 11 Oct 2007 12:36:38 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><p>Dustin Dettmer got the one I was looking for, yet the code provided still did not work <img src="http://www.allegro.cc/forums/smileys/sad.gif" alt=":(" /></p><p>I was trying to get input for the name of the image and load it from a datafile.  So I guess I have to get input as interger instead?
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (The_Wind)</author>
		<pubDate>Fri, 12 Oct 2007 03:17:05 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><p>It should work, what message do you get?<br />(check the manual page for find_datafile_object(), it&#39;s exactly what you asked for. )
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (Audric)</author>
		<pubDate>Fri, 12 Oct 2007 04:03:11 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><p>I think this should do the trick:
</p><div class="source-code snippet"><div class="inner"><pre><a href="http://www.allegro.cc/manual/DATAFILE" target="_blank"><span class="a">DATAFILE</span></a> <span class="k3">*</span>tmp<span class="k2">;</span>
<span class="k1">const</span> <span class="k1">char</span> <span class="k3">*</span>pictureName<span class="k2">;</span>

pictureName <span class="k3">=</span> <span class="s">"COOL_PICTURE"</span><span class="k2">;</span>

tmp <span class="k3">=</span> <a href="http://www.allegro.cc/manual/load_datafile_object" target="_blank"><span class="a">load_datafile_object</span></a><span class="k2">(</span><span class="s">"DatafileName.dat"</span>, pictureName<span class="k2">)</span><span class="k2">;</span>
</pre></div></div><p>

[edit] Fixed.
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (Edward Sheets)</author>
		<pubDate>Fri, 12 Oct 2007 04:09:14 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><p>It was a compile error.  I think it is because that extra &quot;.dat&quot; at the end.  I took it out and it could compile.  </p><div class="source-code snippet"><div class="inner"><pre>string pictureName <span class="k3">=</span> <span class="s">"COOL_PICTURE"</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="k2">;</span>
<a href="http://www.allegro.cc/manual/DATAFILE" target="_blank"><span class="a">DATAFILE</span></a> <span class="k3">*</span>dat<span class="k2">;</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">"myfile.dat"</span><span class="k2">)</span><span class="k2">;</span>
bmp <span class="k3">=</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><span class="k2">)</span><a href="http://www.allegro.cc/manual/find_datafile_object" target="_blank"><span class="a">find_datafile_object</span></a><span class="k2">(</span>dat, pictureName.c_str<span class="k2">(</span><span class="k2">)</span><span class="k2">)</span><span class="k2">;</span>
</pre></div></div><p>

However, it does not load the image I want <img src="http://www.allegro.cc/forums/smileys/sad.gif" alt=":(" /><br />I tried to save the bitmap it loaded, but it just saved a empty bitmap.<br />When I use</p><div class="source-code snippet"><div class="inner"><pre>bmp <span class="k3">=</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><span class="k2">)</span>dat<span class="k2">[</span>COOL_PICTURE<span class="k2">]</span>.dat<span class="k2">;</span>
</pre></div></div><p>

it could actually save the bitmap correctly...</p><p>This is getting me headache now...
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (The_Wind)</author>
		<pubDate>Fri, 12 Oct 2007 04:39:21 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><div class="quote_container"><div class="title">Quote:</div><div class="quote"><p>
<span class="source-code"><a href="http://www.allegro.cc/manual/load_datafile_object" target="_blank"><span class="a">load_datafile_object</span></a><span class="k2">(</span><span class="s">"DatafileName.dat"</span>, pictureName<span class="k2">)</span><span class="k2">;</span></span>
</p></div></div><p>
This sort of thing works too (well, it would work if you stored the return value somewhere), but the problem with this one is that then you&#39;re stuck with a datafile, not a bitmap.</p><p>So, you&#39;ll get memory leaks if you try something like:
</p><div class="source-code snippet"><div class="inner"><pre><a href="http://www.allegro.cc/manual/BITMAP" target="_blank"><span class="a">BITMAP</span></a> <span class="k3">*</span>dont_do_this<span class="k2">(</span><span class="k1">const</span> <span class="k1">char</span> <span class="k3">*</span>df, <span class="k1">const</span> <span class="k1">char</span> <span class="k3">*</span>bmp<span class="k2">)</span> <span class="k2">{</span>
   <a href="http://www.allegro.cc/manual/DATAFILE" target="_blank"><span class="a">DATAFILE</span></a> <span class="k3">*</span>tmp<span class="k2">;</span>
   tmp <span class="k3">=</span> <a href="http://www.allegro.cc/manual/load_datafile_object" target="_blank"><span class="a">load_datafile_object</span></a><span class="k2">(</span>df, bmp<span class="k2">)</span><span class="k2">;</span>
   <span class="k1">return</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><span class="k2">)</span>tmp-&gt;dat<span class="k2">)</span><span class="k2">;</span>
<span class="k2">}</span>
</pre></div></div><p>

As a completely different approach, you could try storing the images in the datafile not as Allegro BITMAP types, but as PCX/BMP/whatever images. (You can just import them as binary files in the grabber)</p><p>Then, do something like:
</p><div class="source-code snippet"><div class="inner"><pre><a href="http://www.allegro.cc/manual/BITMAP" target="_blank"><span class="a">BITMAP</span></a> <span class="k3">*</span>bmp<span class="k2">;</span>
bmp <span class="k3">=</span> <a href="http://www.allegro.cc/manual/load_pcx" target="_blank"><span class="a">load_pcx</span></a><span class="k2">(</span><span class="s">"datafile.dat#PICTURENAME"</span>, NULL<span class="k2">)</span><span class="k2">;</span>
</pre></div></div><p>
The # means &quot;yank this image file out of the datafile,&quot; and it&#39;s handy. <img src="http://www.allegro.cc/forums/smileys/grin.gif" alt=";D" />
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (amber)</author>
		<pubDate>Fri, 12 Oct 2007 05:05:29 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><p>amber<br />My image was &quot;Test.bmp&quot; and it is grabbed and stored in the datafile as COOL_PICTURE.  <br />I tried your stuff but the image cannot be load.  </p><div class="source-code snippet"><div class="inner"><pre><a href="http://www.allegro.cc/manual/BITMAP" target="_blank"><span class="a">BITMAP</span></a> <span class="k3">*</span>bmp<span class="k2">;</span>
bmp <span class="k3">=</span> <a href="http://www.allegro.cc/manual/load_pcx" target="_blank"><span class="a">load_pcx</span></a><span class="k2">(</span><span class="s">"datafile.dat#COOL_PICTURE"</span>, NULL<span class="k2">)</span><span class="k2">;</span>
</pre></div></div><p>
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (The_Wind)</author>
		<pubDate>Fri, 12 Oct 2007 05:43:00 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><p>Are you using that exact code?<br />That is, are you using load_pcx to try to load a .bmp?
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (amber)</author>
		<pubDate>Fri, 12 Oct 2007 08:10:58 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><div class="quote_container"><div class="title">Quote:</div><div class="quote"><p>
the code provided ***** did not work
</p></div></div><p>
I can now see a typo in my code.  This code uses the -&gt; operator insted of the . operator.  Here is the revised code.
</p><div class="source-code snippet"><div class="inner"><pre>string pictureName <span class="k3">=</span> <span class="s">"COOL_PICTURE"</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="k2">;</span>
<a href="http://www.allegro.cc/manual/DATAFILE" target="_blank"><span class="a">DATAFILE</span></a> <span class="k3">*</span>dat<span class="k2">;</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">"myfile.dat"</span><span class="k2">)</span><span class="k2">;</span>
bmp <span class="k3">=</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><span class="k2">)</span><a href="http://www.allegro.cc/manual/find_datafile_object" target="_blank"><span class="a">find_datafile_object</span></a><span class="k2">(</span>dat, pictureName.c_str<span class="k2">(</span><span class="k2">)</span><span class="k2">)</span><span class="k3">-</span><span class="k3">&gt;</span>dat<span class="k2">;</span>
</pre></div></div><p>
As a second chance to learn something, try to associate the error message the compiler gave you with a mistake of . in place of -&gt;.  Next time you see it you may more easily find the error yourself.</p><p><sub>***** the word &#39;still&#39; omitted because my response ignores it and in this context it is grammatically incorrect.</sub>
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (ImLeftFooted)</author>
		<pubDate>Fri, 12 Oct 2007 09:33:10 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><p>The above post may be the most arrogant thing I&#39;ve ever seen on this forum. <img src="http://www.allegro.cc/forums/smileys/grin.gif" alt=";D" /></p><p>The_Wind, the Allegro manual is your friend. Also look at the examples provided with allegro. Combine that with a good book on C/C++ and you&#39;ll find the right solution to your problem. <img src="http://www.allegro.cc/forums/smileys/smiley.gif" alt=":)" />
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (Edward Sheets)</author>
		<pubDate>Fri, 12 Oct 2007 10:07:40 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><p>Thank you all who replied.  I got it to work now. (using Dustin Dettmer&#39;s code).</p><p>I am new to C++ (I used to code in Java), so I still can&#39;t really work with pointers that well.  Sorry if my questions sounded amateur.</p><p>I now have a new question (don&#39;t want to start a new thread).  <br />I have done a code to successfully load spritesheets from the datafile.  And I have a code to cut the spritesheets to individual sprites.  <br />I wish to store these sprites into arrays that&#39;s in another class.<br />Well, it did not work.  I think it is because the BITMAP is a pointer or something...   Can anyone help?</p><div class="source-code"><div class="toolbar"></div><div class="inner"><table width="100%"><tbody><tr><td class="number">1</td><td><a href="http://www.allegro.cc/manual/BITMAP" target="_blank"><span class="a">BITMAP</span></a><span class="k3">*</span> temp_bmp<span class="k2">;</span></td></tr><tr><td class="number">2</td><td>SomeClass sc<span class="k2">;</span></td></tr><tr><td class="number">3</td><td>&#160;</td></tr><tr><td class="number">4</td><td><span class="k1">for</span><span class="k2">(</span><span class="k1">int</span> i <span class="k3">=</span> <span class="n">0</span><span class="k2">;</span> i <span class="k3">&lt;</span> <span class="n">10</span><span class="k2">;</span> i<span class="k3">+</span><span class="k3">+</span><span class="k2">)</span></td></tr><tr><td class="number">5</td><td><span class="k2">{</span></td></tr><tr><td class="number">6</td><td>     temp_bmp <span class="k3">=</span> cut_sprite_sheet<span class="k2">(</span>i<span class="k2">)</span><span class="k2">;</span> <span class="c">//some method that successfully load a </span></td></tr><tr><td class="number">7</td><td>                                     <span class="c">//sprite (with load_bitmap) </span></td></tr><tr><td class="number">8</td><td>     </td></tr><tr><td class="number">9</td><td>     <a href="http://www.allegro.cc/manual/draw_sprite" target="_blank"><span class="a">draw_sprite</span></a><span class="k2">(</span><a href="http://www.allegro.cc/manual/screen" target="_blank"><span class="a">screen</span></a>, temp_bmp, <span class="n">0</span>, <span class="n">0</span><span class="k2">)</span><span class="k2">;</span> <span class="c">//test if bitmap was loaded.</span></td></tr><tr><td class="number">10</td><td>                                          <span class="c">//it worked.</span></td></tr><tr><td class="number">11</td><td>&#160;</td></tr><tr><td class="number">12</td><td>     sc.saveSprite<span class="k2">(</span>i, temp_bmp<span class="k2">)</span><span class="k2">;</span>  <span class="c">//method to store bitmap in array.</span></td></tr><tr><td class="number">13</td><td><span class="k2">}</span></td></tr><tr><td class="number">14</td><td><a href="http://www.allegro.cc/manual/destroy_bitmap" target="_blank"><span class="a">destroy_bitmap</span></a><span class="k2">(</span>temp_bmp<span class="k2">)</span><span class="k2">;</span></td></tr><tr><td class="number">15</td><td>&#160;</td></tr><tr><td class="number">16</td><td><a href="http://www.allegro.cc/manual/draw_sprite" target="_blank"><span class="a">draw_sprite</span></a><span class="k2">(</span><a href="http://www.allegro.cc/manual/screen" target="_blank"><span class="a">screen</span></a>, sc.getSprite<span class="k2">(</span><span class="n">0</span><span class="k2">)</span>, <span class="n">50</span>, <span class="n">50</span><span class="k2">)</span><span class="k2">;</span>  <span class="c">//Crashed right here!!!</span></td></tr><tr><td class="number">17</td><td>                                               <span class="c">//seems like sprite was NULL</span></td></tr><tr><td class="number">18</td><td>&#160;</td></tr><tr><td class="number">19</td><td>&#160;</td></tr><tr><td class="number">20</td><td>&#160;</td></tr><tr><td class="number">21</td><td>&#160;</td></tr><tr><td class="number">22</td><td>&#160;</td></tr><tr><td class="number">23</td><td><span class="c">//***SomeClass....</span></td></tr><tr><td class="number">24</td><td><a href="http://www.allegro.cc/manual/BITMAP" target="_blank"><span class="a">BITMAP</span></a><span class="k3">*</span> sprites<span class="k2">[</span><span class="n">10</span><span class="k2">]</span><span class="k2">;</span></td></tr><tr><td class="number">25</td><td>&#160;</td></tr><tr><td class="number">26</td><td><span class="k1">void</span> SomeClass::saveSprite<span class="k2">(</span><span class="k1">int</span> i, <a href="http://www.allegro.cc/manual/BITMAP" target="_blank"><span class="a">BITMAP</span></a><span class="k3">*</span> bmp<span class="k2">)</span></td></tr><tr><td class="number">27</td><td><span class="k2">{</span></td></tr><tr><td class="number">28</td><td>     sprites<span class="k3">&lt;</span>i&gt; <span class="k3">=</span> bmp<span class="k2">;</span></td></tr><tr><td class="number">29</td><td><span class="k2">}</span></td></tr><tr><td class="number">30</td><td>&#160;</td></tr><tr><td class="number">31</td><td><a href="http://www.allegro.cc/manual/BITMAP" target="_blank"><span class="a">BITMAP</span></a><span class="k3">*</span> SomeClass::getSprite<span class="k2">(</span><span class="k1">int</span> i<span class="k2">)</span></td></tr><tr><td class="number">32</td><td><span class="k2">{</span></td></tr><tr><td class="number">33</td><td>     <span class="k1">return</span> sprites<span class="k3">&lt;</span>i&gt;<span class="k2">;</span></td></tr><tr><td class="number">34</td><td><span class="k2">}</span></td></tr><tr><td class="number">35</td><td><span class="c">//***End SomeClass</span></td></tr></tbody></table></div></div><p>
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (The_Wind)</author>
		<pubDate>Sat, 13 Oct 2007 07:42:57 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><p>The line destroy_bitmap(tmp_bmp); is wrong, because it unloads from memory the latest bitmap (sprite[9] now points to a freed BITMAP)</p><p>But that doesn&#39;t explain why sprite[0] is not ok <img src="http://www.allegro.cc/forums/smileys/undecided.gif" alt=":-/" />
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (Audric)</author>
		<pubDate>Sat, 13 Oct 2007 18:12:02 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><p>First of all, <i>use the stl vector</i>. Google it. It will make you happy.</p><p>Secondly, that destroy_bitmap() is probably the problem, depending on how your cut_sprite_sheet(int) is implemented. And either way it should not be there (see previous post).
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (Jonatan Hedborg)</author>
		<pubDate>Sat, 13 Oct 2007 18:26:37 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><p>Wait, you have temp_bmp and tmp_bmp.<br />There&#39;s something fishy there.
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (Audric)</author>
		<pubDate>Sat, 13 Oct 2007 18:42:43 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><div class="quote_container"><div class="title">Audric said:</div><div class="quote"><p>
Wait, you have temp_bmp and tmp_bmp.<br />There&#39;s something fishy there.
</p></div></div><p>

Ah, that was a typo when I posted the simplified code.  Fixed now.</p><p>Taking out the destroy_bitmap(temp_bmp) still did not work.  But I was trying to make a &#39;copy&#39; of the temp_bmp and store it inside an array.  If the array is simply just pointing to the temp_bmp then it does not work the way I want...</p><p>Trying to implement vector now, might take some time.</p><p>//EDIT</p><p>Aghh, what I thought so.  It is a pointer to the temp_bmp that is stored into the array (now, the vector).  So after destroy_bitmap(temp_bmp), the bitmap in the array aslo is gone.</p><p>I loaded the sprite directly to the array in SomeClass now, and it finally worked.  Thank you to all who replied.  I might need to learn more about these pointer sruff...
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (The_Wind)</author>
		<pubDate>Sat, 13 Oct 2007 22:27:07 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><div class="source-code snippet"><div class="inner"><pre><span class="k1">void</span> SomeClass::saveSprite<span class="k2">(</span><span class="k1">int</span> i, <a href="http://www.allegro.cc/manual/BITMAP" target="_blank"><span class="a">BITMAP</span></a><span class="k3">*</span> bmp<span class="k2">)</span>
<span class="k2">{</span>
     sprites<span class="k3">&lt;</span>i&gt; <span class="k3">=</span> bmp<span class="k2">;</span>
<span class="k2">}</span>
</pre></div></div><p>
That does not copy the bitmap. That copies the pointer to a bitmap. It will still &quot;point&quot; at the same memory adress (and therefore the same BITMAP).<br />You copy a bitmap by making a new bitmap of the correct size (create_bitmap(old-&gt;w, old-&gt;h)) and then blitting the old bitmap to the new one.</p><p>Post your cut_sprite_sheet() function.</p><p>Also, please read up on basic C/C++ <img src="http://www.allegro.cc/forums/smileys/smiley.gif" alt=":)" />
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (Jonatan Hedborg)</author>
		<pubDate>Sat, 13 Oct 2007 23:09:35 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><p>Jonatan Hedborg, thanks for reply.  But I got it worked already <img src="http://www.allegro.cc/forums/smileys/cheesy.gif" alt=":D" /></p><p>Yes I will go ahead and read some C++ stuff.  Right now my computer class is just teaching logic...  Something like P -&gt; Q = F,  P = T, Q = F... stuff.</p><p>I have NO idea how does that going to help me programming, but that is required and what I&#39;m learning now.
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (The_Wind)</author>
		<pubDate>Sun, 14 Oct 2007 00:13:17 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><p>Logic is the heart and soul of programming.
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (Edward Sheets)</author>
		<pubDate>Sun, 14 Oct 2007 01:00:33 +0000</pubDate>
	</item>
</rss>
