<?xml version="1.0"?>
<rss version="2.0">
	<channel>
		<title>OpenLayer, ol::Bitmap::destroy()</title>
		<link>http://www.allegro.cc/forums/view/591618</link>
		<description>Allegro.cc Forum Thread</description>
		<webMaster>matthew@allegro.cc (Matthew Leverton)</webMaster>
		<lastBuildDate>Sat, 02 Jun 2007 02:29:27 +0000</lastBuildDate>
	</channel>
	<item>
		<description><![CDATA[<div class="mockup v2"><p>I have been searching the forums a couple of days now and cannot find similar topic, excuse me if there is any which I missed.</p><p>I am having really hard time releasing the memory allocated by the Bitmap objects in my code. Tried to test new/delete functions with the following program:</p><div class="source-code"><div class="toolbar"></div><div class="inner"><table width="100%"><tbody><tr><td class="number">1</td><td><span class="p">#include &lt;allegro.h&gt;</span></td></tr><tr><td class="number">2</td><td><span class="p">#include &lt;OpenLayer.hpp&gt;</span></td></tr><tr><td class="number">3</td><td>&#160;</td></tr><tr><td class="number">4</td><td><span class="k1">int</span> main<span class="k2">(</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>  ol::Setup::SetupProgram<span class="k2">(</span><span class="k1">true</span>,<span class="k1">true</span>,<span class="k1">true</span><span class="k2">)</span><span class="k2">;</span></td></tr><tr><td class="number">7</td><td>  ol::Setup::SetupScreen<span class="k2">(</span> <span class="n">800</span>, <span class="n">600</span>, <span class="k3">!</span>FULLSCREEN, <span class="n">32</span><span class="k2">)</span><span class="k2">;</span> </td></tr><tr><td class="number">8</td><td>&#160;</td></tr><tr><td class="number">9</td><td>  ol::Bitmap<span class="k3">*</span> b <span class="k3">=</span> NULL<span class="k2">;</span></td></tr><tr><td class="number">10</td><td>  <span class="k1">for</span><span class="k2">(</span><span class="k2">;</span><span class="k2">;</span><span class="k2">)</span></td></tr><tr><td class="number">11</td><td>  <span class="k2">{</span></td></tr><tr><td class="number">12</td><td>    b <span class="k3">=</span> <span class="k1">new</span> ol::Bitmap<span class="k2">(</span><span class="s">"Main.tga"</span><span class="k2">)</span><span class="k2">;</span></td></tr><tr><td class="number">13</td><td>    b-&gt;Destroy<span class="k2">(</span><span class="k2">)</span><span class="k2">;</span></td></tr><tr><td class="number">14</td><td>    <span class="k1">delete</span> b<span class="k2">;</span></td></tr><tr><td class="number">15</td><td>  <span class="k2">}</span></td></tr><tr><td class="number">16</td><td>  <span class="k1">return</span> <span class="n">0</span><span class="k2">;</span></td></tr><tr><td class="number">17</td><td><span class="k2">}</span></td></tr><tr><td class="number">18</td><td><a href="http://www.allegro.cc/manual/END_OF_MAIN" target="_blank"><span class="a">END_OF_MAIN</span></a><span class="k2">(</span><span class="k2">)</span></td></tr></tbody></table></div></div><p>

I do not know how to check memory usage of the program after executing it (Windows Task Manager seems pointless), but it is more than obvious the program is leaking memory. Using big image file (something like 4096x4096) and leaving the program running for several minutes leads to never ending hard disk read/write (swap file i guess) and few more minutes leads to system windows message &quot;The system is low on virtual memory&quot;.</p><p>Maybe I am doing something terribly wrong, but I cant figure what. </p><p>Any comments will be greatly appreciated. Thanks in advance!</p><p>P.S. Excuse my poor English, it is not my native <img src="http://www.allegro.cc/forums/smileys/embarassed.gif" alt=":-[" />
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (mengemeto)</author>
		<pubDate>Mon, 28 May 2007 18:25:34 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><p>Task Manager is not pointless. A good way to use it is to execute the program and open task manager. Look for the program process if the mem useage keep on going up when the program is idel that means you have a mem leak. all you have to do is comment out the parts in your code block by block so you sane find the leak. Most of the time it is the founchion the program in preforming that will by the problem.
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (piccolo)</author>
		<pubDate>Mon, 28 May 2007 21:13:57 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><p>Looks like a clear case of memory leakage. <img src="http://www.allegro.cc/forums/smileys/undecided.gif" alt=":-/" />
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (ImLeftFooted)</author>
		<pubDate>Tue, 29 May 2007 01:23:37 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><p>Why do you want to load and delete in a loop like that?
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (BAF)</author>
		<pubDate>Tue, 29 May 2007 21:10:26 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><div class="quote_container"><div class="title">Quote:</div><div class="quote"><p>
Why do you want to load and delete in a loop like that?
</p></div></div><p>
I&#39;m quite sure that was a narrowed down test too see why his game/app keeps growing in memory usage. Sort of a proof of concept <img src="http://www.allegro.cc/forums/smileys/tongue.gif" alt=":P" />
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (ixilom)</author>
		<pubDate>Wed, 30 May 2007 04:15:48 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><p>Declare that you&#39;re using the OpenLayer namespace so you don&#39;t have to scope <tt>ol::</tt> almost every line. <span class="source-code"><span class="k1">using</span> <span class="k1">namespace</span> ol<span class="k2">;</span></span></p><p>I can reproduce the error, even with a much smaller image.</p><p>Infact, it has nothing to do with the pointer.
</p><div class="source-code snippet"><div class="inner"><pre><span class="k1">while</span><span class="k2">(</span><span class="k1">true</span><span class="k2">)</span> <span class="k2">{</span>
  Bitmap b<span class="k2">;</span>
  b.Load<span class="k2">(</span><span class="s">"test.png"</span><span class="k2">)</span><span class="k2">;</span>
  b.Destroy<span class="k2">(</span><span class="k2">)</span><span class="k2">;</span>
<span class="k2">}</span>
</pre></div></div><p>
Has the same effect.
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (Ceagon Xylas)</author>
		<pubDate>Wed, 30 May 2007 14:05:53 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><p>To answer the question about my stupid new/delete loop, I have done it after few hours of pure frustration being unable to find where the heck my program is leeching memory.<br />Anyway, yesterday I downloaded and compiled openlayer-svn-snapshot-20070526.tar.gz and it seems the Bitmap object is no longer leeching memory.</p><p>Probably I need to ask in a new thread, but I will take a shot here. </p><p>My game has background image (different sizes depending on zone the character is in, but generally something like 3000x3000, 4000x2000 etc.), which is split into several 512x512 images.  When the character is moving the program decide which tiles needs to be &quot;active&quot; at the moment and convert them into ol::Bitmap object so they can be visualized. The ol::Bitmap objects are destroyed when they are no longer needed.<br />The problem is converting memory bitmaps (allegro BITMAP*) to OpenLayer bitmaps (ol::Bitmap) seems to take way too much time. For a tile 512x512x32 it takes about 40ms which is not acceptable considering I am doing it in the main game loop. Do I need to revamp my login so I can do the conversion in a separate thread, or there is a workaround which can speed up the conversion?</p><p>Thanks!
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (mengemeto)</author>
		<pubDate>Wed, 30 May 2007 20:05:06 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><p>I&#39;d keep everything as Bitmaps. Using separate threads might help as well, but generally uploading images to video card is slow. </p><p>About the memory leak, either the latest changes to how the memory version of the image is handled has prevented Bitmap from releasing the memory image or the OpenGL implementation leaks memory (doesn&#39;t sound likely). I&#39;ll take a look when I get a chance...
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (Fladimir da Gorf)</author>
		<pubDate>Fri, 01 Jun 2007 13:04:33 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><p>
The memory leak may be due to a malloc not being freed in an old version of the image -&gt;memory card function. I remember pointing it out to you Flad and you fixed it..
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (Richard Phipps)</author>
		<pubDate>Fri, 01 Jun 2007 15:18:40 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><div class="quote_container"><div class="title">Quote:</div><div class="quote"><p>
I&#39;d keep everything as Bitmaps. Using separate threads might help as well, but generally uploading images to video card is slow.
</p></div></div><p>

Keeping everything as ol:Bitmap objects works great indeed, unfortunately the memory needed for all graphics is about 300MB. There are too many NPCs visible at the same time in certain zones and all of them have 50-60 frames Idle loop and a small collection of Ambient animations (3-4 ambients 50-100 frames each). The animations are being kept in the memory compressed (frame by frame) and decompress/visualize on demand.</p><p>I am trying to run the images decompressing/uploading to video memory in a separate thread, but for some strange reason it fails to create a new ol::Bitmap object if the call is not in the main thread. The reason according to openlayer.log is:</p><p>Loading bitmap from an Allegro OL_MEMORY_IMG (Alpha channel: Yes, Convert Magic Pink: No)<br />No OpenGL extensions were found.</p><p>I cant find anything in OpenLayer&#39;s docs about multi-thread usage. Can it be used at all or I am working in a VERY wrong direction. <img src="http://www.allegro.cc/forums/smileys/undecided.gif" alt=":-/" />
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (mengemeto)</author>
		<pubDate>Fri, 01 Jun 2007 21:06:17 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><div class="quote_container"><div class="title">Quote:</div><div class="quote"><p>
Using separate threads might help as well ...
</p></div></div><p>
I couldn&#39;t imagine seperate threads making this faster.
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (ImLeftFooted)</author>
		<pubDate>Fri, 01 Jun 2007 21:27:28 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><div class="quote_container"><div class="title">Quote:</div><div class="quote"><p>
I couldn&#39;t imagine seperate threads making this faster.
</p></div></div><p>

It wont make it faster of course. It would hide the images preparation delay from player though. For example having a NPC animated in an idle loop, and we want to start an ambient animation for it. Decompressing the new animation images takes, lets say 10ms (it is quite simple compression), uploading them into ol::Bitmap objects (multiple objects to minimize memory losses due to power of 2 limitation) takes, lets say 200ms (even more for some animations <img src="http://www.allegro.cc/forums/smileys/sad.gif" alt=":(" /> ). Thats 210ms when main game loop is stalled. It is perfectly acceptable starting the ambient animation to wait for a different thread to prepare the images before actually starting it (keeping the old animation for this NPC playing meanwhile).</p><p>Thats pretty much the idea I am working on, but being unable to load a ol::Bitmap object in a different thread tends to be a problem <img src="http://www.allegro.cc/forums/smileys/angry.gif" alt="&gt;:(" />
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (mengemeto)</author>
		<pubDate>Fri, 01 Jun 2007 21:49:06 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><p>OpenGL doesn&#39;t support multiple threads <img src="http://www.allegro.cc/forums/smileys/lipsrsealed.gif" alt=":-X" />.  You&#39;re pretty much screwed (unless ofcourse you use D3D, but saying that is grounds to get shot around here <img src="http://www.allegro.cc/forums/smileys/tongue.gif" alt=":P" />)
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (ImLeftFooted)</author>
		<pubDate>Fri, 01 Jun 2007 21:52:14 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><p>
50-60 frames for an idle animation??
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (Richard Phipps)</author>
		<pubDate>Sat, 02 Jun 2007 02:29:27 +0000</pubDate>
	</item>
</rss>
