<?xml version="1.0"?>
<rss version="2.0">
	<channel>
		<title>[A5] Bitmap memory leaks (Release video texture failed)</title>
		<link>http://www.allegro.cc/forums/view/615890</link>
		<description>Allegro.cc Forum Thread</description>
		<webMaster>matthew@allegro.cc (Matthew Leverton)</webMaster>
		<lastBuildDate>Wed, 25 Nov 2015 04:39:11 +0000</lastBuildDate>
	</channel>
	<item>
		<description><![CDATA[<div class="mockup v2"><p>I have been trying to pin down some memory leaks and I&#39;ve hit a wall where I need to know more about what Allegro is doing/expecting because this isn&#39;t making sense to me. I believe I&#39;ve narrowed the issue down to being alpha channel related.</p><p>I tested it on a small piece of bitmap initialization code here:</p><div class="source-code snippet"><div class="inner"><pre>Globals.ui_sheet <span class="k3">=</span> <a href="http://www.allegro.cc/manual/al_load_bitmap"><span class="a">al_load_bitmap</span></a><span class="k2">(</span>ui_sheet_file<span class="k2">)</span><span class="k2">;</span>
Globals.cursor_finger <span class="k3">=</span> <a href="http://www.allegro.cc/manual/al_create_sub_bitmap"><span class="a">al_create_sub_bitmap</span></a><span class="k2">(</span>Globals.ui_sheet, <span class="n">0</span>, <span class="n">0</span>, <span class="n">14</span>, <span class="n">13</span><span class="k2">)</span><span class="k2">;</span>
Globals.cursor_arrow_up <span class="k3">=</span> <a href="http://www.allegro.cc/manual/al_create_sub_bitmap"><span class="a">al_create_sub_bitmap</span></a><span class="k2">(</span>Globals.ui_sheet, <span class="n">0</span>, <span class="n">70</span>, <span class="n">11</span>, <span class="n">7</span><span class="k2">)</span><span class="k2">;</span>
Globals.cursor_arrow_right <span class="k3">=</span> <a href="http://www.allegro.cc/manual/al_create_sub_bitmap"><span class="a">al_create_sub_bitmap</span></a><span class="k2">(</span>Globals.ui_sheet, <span class="n">0</span>, <span class="n">41</span>, <span class="n">12</span>, <span class="n">11</span><span class="k2">)</span><span class="k2">;</span>
<span class="c">/* Initialize a bunch more icons here....*/</span>

<a href="http://www.allegro.cc/manual/al_convert_mask_to_alpha"><span class="a">al_convert_mask_to_alpha</span></a><span class="k2">(</span>Globals.cursor_finger, COLOR_TRANSPARENCY<span class="k2">)</span><span class="k2">;</span>
<a href="http://www.allegro.cc/manual/al_convert_mask_to_alpha"><span class="a">al_convert_mask_to_alpha</span></a><span class="k2">(</span>Globals.cursor_arrow_up, COLOR_TRANSPARENCY<span class="k2">)</span><span class="k2">;</span>
<a href="http://www.allegro.cc/manual/al_convert_mask_to_alpha"><span class="a">al_convert_mask_to_alpha</span></a><span class="k2">(</span>Globals.cursor_arrow_right, COLOR_TRANSPARENCY<span class="k2">)</span><span class="k2">;</span>
<span class="c">/* Convert alpha mask for all of them here...*/</span>

<a href="http://www.allegro.cc/manual/al_destroy_bitmap"><span class="a">al_destroy_bitmap</span></a><span class="k2">(</span>Globals.ui_sheet<span class="k2">)</span><span class="k2">;</span>
</pre></div></div><p>

I&#39;ve messed around with the timing of the alpha mask function and the delete function, and if I delete the parent bitmap before calling <tt>al_convert_mask_to_alpha</tt>, then I don&#39;t get the log messages saying &quot;<tt>Release video texture failed. Release render target failed.</tt>&quot;</p><p>This is what the allegro.log file spits out when I&#39;m initializing most of my bitmaps, and I&#39;m not sure if it means I&#39;m doing something wrong, but the presence of &quot;<tt>Alpha doesn&#39;t match</tt>&quot; also led me to think it&#39;s alpha channel related:</p><div class="source-code snippet"><div class="inner"><pre>d3d      D         d3d_disp.cpp:1166 real_choose_bitmap_format        <span class="k2">[</span>   <span class="n">1</span>.<span class="n">07354</span><span class="k2">]</span> Fake format
d3d      D         d3d_disp.cpp:1166 real_choose_bitmap_format        <span class="k2">[</span>   <span class="n">1</span>.<span class="n">07359</span><span class="k2">]</span> Fake format
d3d      D         d3d_disp.cpp:1166 real_choose_bitmap_format        <span class="k2">[</span>   <span class="n">1</span>.<span class="n">07363</span><span class="k2">]</span> Fake format
d3d      D         d3d_disp.cpp:1166 real_choose_bitmap_format        <span class="k2">[</span>   <span class="n">1</span>.<span class="n">07367</span><span class="k2">]</span> Fake format
d3d      D         d3d_disp.cpp:1166 real_choose_bitmap_format        <span class="k2">[</span>   <span class="n">1</span>.<span class="n">07370</span><span class="k2">]</span> Fake format
d3d      D         d3d_disp.cpp:1166 real_choose_bitmap_format        <span class="k2">[</span>   <span class="n">1</span>.<span class="n">07374</span><span class="k2">]</span> Fake format
d3d      D         d3d_disp.cpp:1166 real_choose_bitmap_format        <span class="k2">[</span>   <span class="n">1</span>.<span class="n">07377</span><span class="k2">]</span> Fake format
d3d      D         d3d_disp.cpp:1166 real_choose_bitmap_format        <span class="k2">[</span>   <span class="n">1</span>.<span class="n">07381</span><span class="k2">]</span> Fake format
d3d      D         d3d_disp.cpp:1166 real_choose_bitmap_format        <span class="k2">[</span>   <span class="n">1</span>.<span class="n">07384</span><span class="k2">]</span> Fake format
d3d      D         d3d_disp.cpp:1174 real_choose_bitmap_format        <span class="k2">[</span>   <span class="n">1</span>.<span class="n">07388</span><span class="k2">]</span> Alpha doesn<span class="s">'t match</span>
<span class="s">d3d      D         d3d_disp.cpp:1181 real_choose_bitmap_format        [   1.07391] Adapter format is 23</span>
<span class="s">d3d      D         d3d_disp.cpp:1184 real_choose_bitmap_format        [   1.07396] Found a format</span>
<span class="s">d3d      I         d3d_disp.cpp:2283 _al_d3d_create_bitmap            [   1.07399] Chose bitmap format 9</span>
<span class="s">dtor     D               dtor.c:184  _al_register_destructor          [   1.07486] added dtor for object 05AA1FE8, func 0055DC32</span>
</pre></div></div><p>

I have a last simple question: do I need to call <tt>al_destroy_bitmap</tt> on bitmaps created from <tt>al_create_sub_bitmap</tt>? From the documentation it sounded like no, but I just wanted to make sure.
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (9inchsamurai)</author>
		<pubDate>Mon, 23 Nov 2015 03:51:20 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><p>All bitmaps in principle register their destructor ( <span class="source-code"><a href="http://www.allegro.cc/manual/al_destroy_bitmap"><span class="a">al_destroy_bitmap</span></a></span> ) in a global list that gets called when Allegro shuts down (after your main function exits). It&#39;s possible that this might confuse a memory leak detector, so it&#39;s encouraged to destroy them all manually. In the case of sub bitmaps, they also need to be destroyed via <span class="source-code"><a href="http://www.allegro.cc/manual/al_destroy_bitmap"><span class="a">al_destroy_bitmap</span></a></span> (automatically or manually by you).</p><p>Destroying the <span class="source-code">ui_sheet</span> seems like a very bad idea, as it will invalidate the sub-bitmaps. I&#39;m surprised that it works. The logging statements you see are probably harmless (they are prefixed with &#39;D&#39; which means debug), they just show how the D3D backend is trying different formats when creating the bitmap.
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (SiegeLord)</author>
		<pubDate>Mon, 23 Nov 2015 04:35:05 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><div class="quote_container"><div class="title"><a href="http://www.allegro.cc/forums/thread/615890/1018003#target">SiegeLord</a> said:</div><div class="quote"><p>In the case of sub bitmaps, they also need to be destroyed via al_destroy_bitmap (automatically or manually by you).</p></div></div><p>

This could be the cause of my memory leaks because I know I&#39;m creating some sub bitmaps and not retaining pointers to them to be deleted later. I only added <tt>al_destroy_bitmap(ui_sheet)</tt> as a test there to see what the log would say to me. The documentation for <tt>al_create_sub_bitmap</tt> made it seem like Allegro would automatically handle memory management when I delete the parent bitmap.
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (9inchsamurai)</author>
		<pubDate>Mon, 23 Nov 2015 04:46:12 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><p>It deletes the parent bitmap and its memory, but not each sub bitmap&#39;s structure. Its a low amount of memory per sub bitmap, but they will still leak if you don&#39;t free them.
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (Thomas Fjellstrom)</author>
		<pubDate>Mon, 23 Nov 2015 05:53:16 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><p>Right, the documentation for <span class="source-code"><a href="http://www.allegro.cc/manual/al_create_sub_bitmap"><span class="a">al_create_sub_bitmap</span></a></span> refers to the pixel data, but there&#39;s still some memory for each sub-bitmap to store things like its width and a pointer back to the parent bitmap, amongst a few other things.
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (SiegeLord)</author>
		<pubDate>Mon, 23 Nov 2015 06:04:24 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><div class="quote_container"><div class="title"><a href="http://www.allegro.cc/forums/thread/615890/1018006#target">Thomas Fjellstrom</a> said:</div><div class="quote"><p>It deletes the parent bitmap and its memory, but not each sub bitmap&#39;s structure. Its a low amount of memory per sub bitmap, but they will still leak if you don&#39;t free them.</p></div></div><p>

Ah okay. Well, I know this is happening every render frame during a specific game state, so that will easily add up over time.</p><p>So, do I not need to be worried about the Allegro log telling me
</p><div class="source-code snippet"><div class="inner"><pre>d3d_destroy_bitmap: Release video texture failed.
d3d_destroy_bitmap: Release render target failed.
</pre></div></div><p>
after I destroy some of these bitmaps?
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (9inchsamurai)</author>
		<pubDate>Mon, 23 Nov 2015 06:09:08 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><p>Those would probably be indicative of bugs in Allegro, rather than in your code. Just t be clear, what version of it are you using?
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (SiegeLord)</author>
		<pubDate>Mon, 23 Nov 2015 06:42:02 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><p>I&#39;m using 5.0.10.
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (9inchsamurai)</author>
		<pubDate>Mon, 23 Nov 2015 06:52:25 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><p>5.0.10 is a bit old, and we have fixed a whole bunch of leaks since (not necessarily these though, I haven&#39;t checked). There&#39;s some MinGW binaries of the newest version towards the end of this thread <a href="https://www.allegro.cc/forums/thread/615781/1018005#target">https://www.allegro.cc/forums/thread/615781/1018005#target</a> if you want to try them (and also MSVC libraries up top as well).
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (SiegeLord)</author>
		<pubDate>Tue, 24 Nov 2015 08:44:42 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><p>Thanks. I haven&#39;t updated to 5.1 at all because I don&#39;t check the forums for newest versions and just look at the main page. I&#39;ll be sure to do that from now on.
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (9inchsamurai)</author>
		<pubDate>Wed, 25 Nov 2015 04:39:11 +0000</pubDate>
	</item>
</rss>
