<?xml version="1.0"?>
<rss version="2.0">
	<channel>
		<title>Destroying an array of bitmaps</title>
		<link>http://www.allegro.cc/forums/view/615973</link>
		<description>Allegro.cc Forum Thread</description>
		<webMaster>matthew@allegro.cc (Matthew Leverton)</webMaster>
		<lastBuildDate>Tue, 12 Jan 2016 18:44:13 +0000</lastBuildDate>
	</channel>
	<item>
		<description><![CDATA[<div class="mockup v2"><p>So I&#39;m making a game with a tiled background, and using this for it:<br /> 	<span class="source-code"><a href="http://www.allegro.cc/manual/ALLEGRO_BITMAP"><span class="a">ALLEGRO_BITMAP</span></a> <span class="k3">*</span>tileVisible<span class="k2">[</span>TILE_GRID_HEIGHT<span class="k2">]</span><span class="k2">[</span>TILE_GRID_WIDTH<span class="k2">]</span><span class="k2">;</span></span></p><p>But I get &quot;Access Violation&quot; when I try to destroy the bitmaps:<br /> 	</p><div class="source-code"><div class="toolbar"><span class="button numbers"><b>#</b></span><span class="button select">Select</span><span class="button expand">Expand</span></div><div class="inner"><span class="number"> 1</span><span class="k1">for</span> <span class="k2">(</span>i <span class="k3">=</span> <span class="n">0</span><span class="k2">;</span> i <span class="k3">&lt;</span> TILE_GRID_HEIGHT<span class="k2">;</span> i<span class="k3">+</span><span class="k3">+</span><span class="k2">)</span>
<span class="number"> 2</span>  <span class="k2">{</span>
<span class="number"> 3</span>    <span class="k1">for</span> <span class="k2">(</span>k <span class="k3">=</span> <span class="n">0</span><span class="k2">;</span> k <span class="k3">&lt;</span> TILE_GRID_WIDTH<span class="k2">;</span> k<span class="k3">+</span><span class="k3">+</span><span class="k2">)</span>
<span class="number"> 4</span>    <span class="k2">{</span>
<span class="number"> 5</span>      <a href="http://www.allegro.cc/manual/al_destroy_bitmap"><span class="a">al_destroy_bitmap</span></a><span class="k2">(</span>tileVisible<span class="k2">[</span>i<span class="k2">]</span><span class="k2">[</span>k<span class="k2">]</span><span class="k2">)</span><span class="k2">;</span>
<span class="number"> 6</span>    <span class="k2">}</span>
<span class="number"> 7</span>  <span class="k2">}</span>
</div></div><p>

Obviously I&#39;m doing something wrong, but I can&#39;t figure out what.
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (DreamCloud)</author>
		<pubDate>Thu, 07 Jan 2016 10:43:56 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><p>If I were a betting man, I&#39;d guess you were destroying a bitmap more than once. In your tilemap, where you have repeated blocks, are they pointers to the <i>same</i> bitmap or identical copies of that bitmap?
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (Peter Hull)</author>
		<pubDate>Thu, 07 Jan 2016 15:17:09 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><p>Ah, you&#39;re right. I load each different tile once separately and point to them multiple times for the map. Ugh, I can&#39;t believe I missed that.</p><p>Thanks for the help!
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (DreamCloud)</author>
		<pubDate>Thu, 07 Jan 2016 21:30:37 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><p>You should load your bitmaps in an array.</p><p>then on the map sectors you only need to store the number of the bitmap used.</p><p>then when drawing, just look at the number and you will know what bitmap to draw.<br />to change the bitmap, simply change the number on that square and the tile will change with no loading etc.</p><p>When loading the array, if you malloc it, you can have unlimited bitmaps, and if you save the bitmaps something like bitmap1.bmp, bitmap2.bmp ...<br />its very easy to cycle through a folder trying to load bitmaps until you fail, this will tell you how many bitmaps you have, so you will know how much space to allocate then load them.</p><p>This way, to add new bitmaps, all you have to do is drop them into the folder and your code will automatically load them and assign them a value.</p><p>There are many more changes you can make to this, so that you can load related graphics, ie graphic type 1 is grass, so any graphics i call bitmap 1_X.bmp will be treated the same, so when you paste down grass, you know type 1 is grass, there might be 1 or 30 grass images, provided you also keep the frame number, you could easily do animation, or just simple random grass tiles etc.
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (duncan perham)</author>
		<pubDate>Tue, 12 Jan 2016 18:44:13 +0000</pubDate>
	</item>
</rss>
