<?xml version="1.0"?>
<rss version="2.0">
	<channel>
		<title>al_destroy_sample crash</title>
		<link>http://www.allegro.cc/forums/view/616796</link>
		<description>Allegro.cc Forum Thread</description>
		<webMaster>matthew@allegro.cc (Matthew Leverton)</webMaster>
		<lastBuildDate>Wed, 15 Mar 2017 12:45:03 +0000</lastBuildDate>
	</channel>
	<item>
		<description><![CDATA[<div class="mockup v2"><p>I&#39;m having an issue when I try to destroy an audio sample.  I create and load the sample in a class.  It plays just fine, but for some reason the program crashes when the destructor tries to destroy the sample.</p><p>Here&#39;s how my code is generally setup.
</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>Class Player<span class="k2">{</span>
<span class="number">  2</span>public:
<span class="number">  3</span>  player<span class="k2">(</span><span class="k2">)</span><span class="k2">{</span>
<span class="number">  4</span>    image1 <span class="k3">=</span> al_load_image<span class="k2">(</span><span class="s">"Assets/Image1.png"</span><span class="k2">)</span><span class="k2">;</span>
<span class="number">  5</span>    image2 <span class="k3">=</span> al_load_image<span class="k2">(</span><span class="s">"Assets/Image2.png"</span><span class="k2">)</span><span class="k2">;</span>
<span class="number">  6</span>    <span class="k1">if</span><span class="k2">(</span><span class="k3">!</span>image1<span class="k2">)</span><span class="k2">{</span>
<span class="number">  7</span>       Error handling code
<span class="number">  8</span>    <span class="k2">}</span>
<span class="number">  9</span>    <span class="k1">if</span><span class="k2">(</span><span class="k3">!</span>image2<span class="k2">)</span><span class="k2">{</span>
<span class="number"> 10</span>       Error handling code
<span class="number"> 11</span>    <span class="k2">}</span>
<span class="number"> 12</span>
<span class="number"> 13</span>    audio_fireball <span class="k3">=</span> <a href="http://www.allegro.cc/manual/al_load_sample"><span class="a">al_load_sample</span></a><span class="k2">(</span><span class="s">"Assets/fireball.ogg"</span><span class="k2">)</span><span class="k2">;</span>
<span class="number"> 14</span>    <span class="k1">if</span><span class="k2">(</span><span class="k3">!</span>audio_fireball<span class="k2">)</span><span class="k2">{</span>
<span class="number"> 15</span>       Error handling code
<span class="number"> 16</span>    <span class="k2">}</span>
<span class="number"> 17</span>  <span class="k2">}</span>
<span class="number"> 18</span>
<span class="number"> 19</span>  ~player<span class="k2">(</span><span class="k2">)</span><span class="k2">{</span>
<span class="number"> 20</span>     <a href="http://www.allegro.cc/manual/al_destroy_bitmap"><span class="a">al_destroy_bitmap</span></a><span class="k2">(</span>image1<span class="k2">)</span><span class="k2">;</span>
<span class="number"> 21</span>     <a href="http://www.allegro.cc/manual/al_destroy_bitmap"><span class="a">al_destroy_bitmap</span></a><span class="k2">(</span>image2<span class="k2">)</span><span class="k2">;</span>
<span class="number"> 22</span>     std::cout <span class="k3">&lt;</span><span class="k3">&lt;</span> <span class="s">"Destroyed Images"</span> <span class="k3">&lt;</span><span class="k3">&lt;</span> std::endl<span class="k2">;</span> <span class="c">//just used to test the error</span>
<span class="number"> 23</span>
<span class="number"> 24</span>     <a href="http://www.allegro.cc/manual/al_destroy_sample"><span class="a">al_destroy_sample</span></a><span class="k2">(</span>audio_fireball<span class="k2">)</span><span class="k2">;</span>
<span class="number"> 25</span>     std::cout <span class="k3">&lt;</span><span class="k3">&lt;</span> <span class="s">"Destroyed Sample"</span> <span class="k3">&lt;</span><span class="k3">&lt;</span> std::endl<span class="k2">;</span> <span class="c">//Also to test error</span>
<span class="number"> 26</span>   <span class="k2">}</span>
<span class="number"> 27</span>
<span class="number"> 28</span>private:
<span class="number"> 29</span>
<span class="number"> 30</span>  <a href="http://www.allegro.cc/manual/ALLEGRO_BITMAP"><span class="a">ALLEGRO_BITMAP</span></a> <span class="k3">*</span>image1 <span class="k3">=</span> NULL<span class="k2">;</span>
<span class="number"> 31</span>  <a href="http://www.allegro.cc/manual/ALLEGRO_BITMAP"><span class="a">ALLEGRO_BITMAP</span></a> <span class="k3">*</span>image2 <span class="k3">=</span> NULL<span class="k2">;</span>
<span class="number"> 32</span>
<span class="number"> 33</span>  <a href="http://www.allegro.cc/manual/ALLEGRO_SAMPLE"><span class="a">ALLEGRO_SAMPLE</span></a> <span class="k3">*</span>audio_fireball <span class="k3">=</span> NULL<span class="k2">;</span>
<span class="number"> 34</span>
<span class="number"> 35</span><span class="k2">}</span>
</div></div><p>
The cout after destroying the bitmaps displays, but the cout after the sample doesn&#39;t.  I also did a al_is_audio_installed check right before trying to destroy the sample and it returned true.
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (Trenchman)</author>
		<pubDate>Tue, 14 Mar 2017 10:35:57 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><p>What do you mean with &quot;crash&quot;?  Does it return an error message?  Did you try to debug it (i.e. GDB)?
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (Niunio)</author>
		<pubDate>Tue, 14 Mar 2017 15:08:30 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><p>Does your Player class happen to be instantiated as a global?
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (Polybios)</author>
		<pubDate>Tue, 14 Mar 2017 18:18:28 +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/616796/1028972#target">Polybios</a> said:</div><div class="quote"><p>
Does your Player class happen to be instantiated as a global?
</p></div></div><p>
To add to that. If it is, it&#39;ll attempt to call Allegro functions... before Allegro is initialized = boom.
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (Chris Katko)</author>
		<pubDate>Wed, 15 Mar 2017 00:53:51 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><p>Yeah, that&#39;s true. I probably should have said &quot;could have something to do with order of destruction&quot;.
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (Polybios)</author>
		<pubDate>Wed, 15 Mar 2017 03:47:37 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><p>I suppose I should also mention I&#39;m using allegro 5.0.10 on a windows PC and building with Code:Blocks and MinGW.</p><p>It gives me an error window, and returns -1073741819.</p><p>I create the instance inside the main function after all of the Allegro initialization is finished.  Everything seems to work fine, and destroying the images I&#39;ve loaded works fine.  Just when I try to destroy the sample it crashes.</p><p>Edit:<br />Well, I&#39;m an idiot.  For some reason I put al_uninstall_audio right before the end of main and didn&#39;t think I did.  I used al_is_audio_installed to make sure it was still installed immediately before destroying the samples and it returned true.  But, I think it may return true even if it isn&#39;t currently installed, as long as it was successfully installed earlier in the program.  Sorry guys.
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (Trenchman)</author>
		<pubDate>Wed, 15 Mar 2017 12:45:03 +0000</pubDate>
	</item>
</rss>
