<?xml version="1.0"?>
<rss version="2.0">
	<channel>
		<title>Occasional hang in al_detach_voice()  when closing my application</title>
		<link>http://www.allegro.cc/forums/view/611151</link>
		<description>Allegro.cc Forum Thread</description>
		<webMaster>matthew@allegro.cc (Matthew Leverton)</webMaster>
		<lastBuildDate>Mon, 01 Oct 2012 17:39:20 +0000</lastBuildDate>
	</channel>
	<item>
		<description><![CDATA[<div class="mockup v2"><p>Hi there!</p><p>Please can somebody help me! Finished my game, but I just have this one bug that I can&#39;t seem to fix. When I quit my game, my code does the following:</p><p>step 1 - Iterates through my list of sounds instances, stopping and destroying them. <br />step 2 - detaches the voice and the mixer<br />step 3 - destroys the voice and the mixer</p><p>Very occasionally my code hangs in al_detach_voice(). I&#39;d say it happens about once every 30 game runs. Seems to happen more when running a Release build. Hardly ever happens when running a debug build.</p><p>Even though I was pretty sure I was detaching things in the correct order, I decided to see what happened if I detached the mixer before the voice. Running a debug build I must have started and stopped my application about 50 times, until eventually I got it to hang. I have attached the stack trace below. Unfortunately, I don&#39;t have stack trace of when I was detaching the voice before the mixer (but hopefully you can see from the stack trace attached, the first thing al_detach_mixer() does if the voice is not detached, is call al_detach_voice()):</p><p>ntdll.dll!_KiFastSystemCallRet@0() 	<br /> 	ntdll.dll!_NtWaitForSingleObject@12()  + 0xc bytes	<br /> 	kernel32.dll!_WaitForSingleObjectEx@12()  + 0x8b bytes	<br /> 	kernel32.dll!_WaitForSingleObject@8()  + 0x12 bytes	<br /> 	allegro-5.0.7-monolith-md-debug.dll!_al_thread_join(_AL_THREAD * thread=0x00fe3760)  Line 80	C<br /> 	allegro-5.0.7-monolith-md-debug.dll!al_join_thread(ALLEGRO_THREAD * thread=0x00fe3760, void * * ret_value=0x00000000)  Line 201 + 0x9 bytes	C<br /> 	allegro-5.0.7-monolith-md-debug.dll!_dsound_stop_voice(ALLEGRO_VOICE * voice=0x00fe34d8)  Line 456 + 0xe bytes	C++<br /> 	allegro-5.0.7-monolith-md-debug.dll!al_detach_voice(ALLEGRO_VOICE * voice=0x00fe34d8)  Line 376 + 0xf bytes	C<br /> 	allegro-5.0.7-monolith-md-debug.dll!_al_kcm_detach_from_parent(ALLEGRO_SAMPLE_INSTANCE * spl=0x00fe3628)  Line 116 + 0xf bytes	C<br /> 	allegro-5.0.7-monolith-md-debug.dll!al_detach_mixer(ALLEGRO_MIXER * mixer=0x00fe3628)  Line 1257 + 0x9 bytes	C<br /> 	monaco79.exe!game_audio::uninit()  Line 1857 + 0x12 bytes	C++<br /> 	monaco79.exe!main(int argc=1, const char * * argv=0x00ac62a8)  Line 5697	C++<br /> 	monaco79.exe!__tmainCRTStartup()  Line 586 + 0x19 bytes	C<br /> 	monaco79.exe!mainCRTStartup()  Line 403	C<br /> 	kernel32.dll!_BaseProcessStart@4()  + 0x23 bytes</p><p>I&#39;m a bit concerned as the bug sounds <b>exactly</b> like this one entitled &quot;(A5) random crash on al_detach_voice()&quot; which doesn&#39;t look as if it was ever resolved:<br /><a href="http://www.allegro.cc/forums/thread/610569">http://www.allegro.cc/forums/thread/610569</a></p><p>Hope someone can help, many thanks if you read this far! <img src="http://www.allegro.cc/forums/smileys/smiley.gif" alt=":)" /></p><p>Ben
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (monacogp)</author>
		<pubDate>Fri, 28 Sep 2012 23:51:13 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><p>Are you running this on Windows XP?  </p><p>I only had my issue on XP.  Never had it on Win 7 or iOS.
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (thebignic)</author>
		<pubDate>Sat, 29 Sep 2012 00:03:14 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><p>Hi!</p><p>I&#39;ve seen it hang On WinXP and Vista. I have a mate who&#39;s running my game on window 7 and he hasn&#39;t seen the hang yet..
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (monacogp)</author>
		<pubDate>Sat, 29 Sep 2012 00:31:27 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><p>It&#39;s most likely a bug in Allegro. Can you make a small test case to reproduce the issue?</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="p">#include &lt;allegro5/allegro.h&gt;</span>
<span class="number">  2</span><span class="p">#include &lt;allegro5/allegro_audio.h&gt;</span>
<span class="number">  3</span><span class="p">#include &lt;allegro5/allegro_native_dialog.h&gt;</span>
<span class="number">  4</span><span class="p">#include &lt;stdio.h&gt;</span>
<span class="number">  5</span>
<span class="number">  6</span><span class="k1">int</span> main<span class="k2">(</span><span class="k1">void</span><span class="k2">)</span>
<span class="number">  7</span><span class="k2">{</span>
<span class="number">  8</span>    <a href="http://www.allegro.cc/manual/ALLEGRO_TEXTLOG"><span class="a">ALLEGRO_TEXTLOG</span></a> <span class="k3">*</span><a href="http://www.delorie.com/djgpp/doc/libc/libc_542.html" target="_blank">log</a><span class="k2">;</span>
<span class="number">  9</span>    <span class="k1">int</span> i<span class="k2">;</span>
<span class="number"> 10</span>
<span class="number"> 11</span>    <a href="http://www.allegro.cc/manual/al_init"><span class="a">al_init</span></a><span class="k2">(</span><span class="k2">)</span><span class="k2">;</span>
<span class="number"> 12</span>    <a href="http://www.delorie.com/djgpp/doc/libc/libc_542.html" target="_blank">log</a> <span class="k3">=</span> <a href="http://www.allegro.cc/manual/al_open_native_text_log"><span class="a">al_open_native_text_log</span></a><span class="k2">(</span><span class="s">"stress test"</span>, ALLEGRO_TEXTLOG_NO_CLOSE<span class="k2">)</span><span class="k2">;</span>
<span class="number"> 13</span>    <span class="k1">for</span> <span class="k2">(</span>i <span class="k3">=</span> <span class="n">0</span><span class="k2">;</span> <span class="k2">;</span> i<span class="k3">+</span><span class="k3">+</span><span class="k2">)</span> <span class="k2">{</span>
<span class="number"> 14</span>        <a href="http://www.allegro.cc/manual/al_install_audio"><span class="a">al_install_audio</span></a><span class="k2">(</span><span class="k2">)</span><span class="k2">;</span>
<span class="number"> 15</span>        <a href="http://www.allegro.cc/manual/al_reserve_samples"><span class="a">al_reserve_samples</span></a><span class="k2">(</span><span class="n">16</span><span class="k2">)</span><span class="k2">;</span>
<span class="number"> 16</span><span class="c">//      al_rest(0.001);</span>
<span class="number"> 17</span>        <a href="http://www.allegro.cc/manual/al_uninstall_audio"><span class="a">al_uninstall_audio</span></a><span class="k2">(</span><span class="k2">)</span><span class="k2">;</span>
<span class="number"> 18</span>        <a href="http://www.allegro.cc/manual/al_append_native_text_log"><span class="a">al_append_native_text_log</span></a><span class="k2">(</span><a href="http://www.delorie.com/djgpp/doc/libc/libc_542.html" target="_blank">log</a>, <span class="s">"%d\n"</span>, i<span class="k2">)</span><span class="k2">;</span>
<span class="number"> 19</span>    <span class="k2">}</span>
<span class="number"> 20</span>    <span class="k1">return</span> <span class="n">0</span><span class="k2">;</span>
<span class="number"> 21</span><span class="k2">}</span>
</div></div><p>

Also, I added quite a few logging statements to the DirectSound driver on the 5.1 branch just now. If you can, build with Allegro in debug mode and post the allegro.log file when you get a crash.
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (Peter Wang)</author>
		<pubDate>Sat, 29 Sep 2012 06:56:58 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><p>Sure thing, I&#39;d be happy to give that a try :O) But please forgive me, but I&#39;m having trouble working out how to build allegro :O( </p><p>You said you&#39;d made some recent changes to the 5.1 branch. Where can I get those? </p><p>I found a link to some 5.1.3 unstable sources (here <a href="http://sourceforge.net/projects/alleg/files/allegro-unstable/">http://sourceforge.net/projects/alleg/files/allegro-unstable/</a>), so I decided a good place to start would be to see if I could build these first.</p><p>I read the README_msvc.txt, I&#39;m building with MSVC 2008, I&#39;ve got the Microsoft SDKs v6.0A and v7.0A installed, I have the DirectX SDK (June 2010) installed. </p><p>I went to my c:\allergo_src\build directory and typed &quot;cmake-gui ..&quot;, chose to do a vc9.0 (2008) build, clicked configure and got lots of warnings:-<br />Using VCINSTALLDIR: C:/Program Files/Microsoft Visual Studio 9.0/VC<br />Allowing MSVC to use SSE instructions<br />Could NOT find PkgConfig (missing:  PKG_CONFIG_EXECUTABLE) <br />Could NOT find OpenAL (missing:  OPENAL_LIBRARY OPENAL_INCLUDE_DIR) <br />Could NOT find FLAC (missing:  FLAC_INCLUDE_DIR OGG_LIBRARY FLAC_LIBRARY) <br />WARNING: libFLAC not found or compile test failed, disabling support.<br />Could NOT find DUMB (missing:  DUMB_INCLUDE_DIR DUMB_LIBRARY) <br />WARNING: libdumb not found or compile test failed, disabling support. &lt;<a href="http://dumb.sourceforge.net/">http://dumb.sourceforge.net/</a>&gt;<br />Could NOT find OGG (missing:  OGG_INCLUDE_DIR OGG_LIBRARY) <br />WARNING: libvorbis not found or compile test failed, disabling support.<br />Could NOT find Freetype (missing:  FREETYPE_LIBRARY FREETYPE_INCLUDE_DIRS) <br />WARNING: FreeType not found, disabling support.<br />Could NOT find PhysFS (missing:  PHYSFS_LIBRARY PHYSFS_INCLUDE_DIR) <br />Could NOT find PHYSFS (missing:  PHYSFS_LIBRARY PHYSFS_INCLUDE_DIR) <br />Could NOT find OGG (missing:  OGG_INCLUDE_DIR OGG_LIBRARY) <br />Could NOT find OGG (missing:  OGG_INCLUDE_DIR OGG_LIBRARY) <br />WARNING: allegro_video wanted but no supported backend found<br />Not building skater demo<br />Not building ex_color<br />Not building ex_depth_mask<br />Not building ex_physfs<br />Not building ex_video<br />Not building ex_font_justify<br />Not building ex_logo<br />Not building ex_projection<br />Not building ex_ttf<br />Not building ex_audio_chain<br />Not building ex_synth<br />Not building tests due to missing library. Have: allegro allegro_main allegro_image allegro_color allegro_font  allegro_primitives<br />Configuring done</p><p>Do I need to sort out all of these warnings to in order to build allegro? Am I on the right track?? I feel a bit stupid :OP</p><p>Many thanks,</p><p>Ben
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (monacogp)</author>
		<pubDate>Sat, 29 Sep 2012 23:48:55 +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/611151/967098#target">monacogp</a> said:</div><div class="quote"><p>You said you&#39;d made some recent changes to the 5.1 branch. Where can I get those?</p></div></div><p>You&#39;ll want to check out the files from the version control repo: <a href="http://www.liballeg.org/git.html">http://www.liballeg.org/git.html</a></p><div class="quote_container"><div class="title">Quote:</div><div class="quote"><p>Do I need to sort out all of these warnings to in order to build allegro? Am I on the right track?? I feel a bit stupid :OP</p></div></div><p>You only need to care about those warnings if you want to use the addons that caused those warnings.
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (Thomas Fjellstrom)</author>
		<pubDate>Sun, 30 Sep 2012 03:01:37 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><p>Hi there! Thanks for the help, I managed to run Peter&#39;s test using the 5.1 source I git from <a href="http://www.liballeg.org/git.html">http://www.liballeg.org/git.html</a> :O)</p><p>First I built the 5.1 sources and test code in Debug mode, I let the test run for about 15mins, it did about 50000 iterations of the for loop. The logfile grew to about 200MB, but it didn&#39;t crash/hang so I stopped it.</p><p>I then decided to build the 5.1 sources and test code Release mode (just wanted to see if I could get it to crash/hang using the 5.1 sources). Could only figure out how to build allegro in RelWithDebInfo DLLs so I used those. Left the test running for 15mins, but it still didn&#39;t crash/hang within that time so I stopped it.</p><p>I then decided to build the test code with my 5.0.7 Debug sources (pre-built ones I downloaded a while ago). Left the test for 15mins, no crash/hang within that time.</p><p>I then decided to build the test code with my 5.0.7 Release sources. It hung immediately in al_unistall_audio(). <b>But</b> I noticed if I commented in the &quot;al_rest(0.001)&quot; line it would run fine.</p><p>One thing that is probably not worth mentioning, when using the 5.1 sources, if I clicked on any minimized window on my task bar while running the test, it trigged the assert call stack below. After I read what was in the call stack, I just made sure I didn&#39;t click on anything during subsequent test runs.</p><p> 	msvcr90d.dll!_NMSG_WRITE(int rterrnum=10)  Line 198	C<br /> 	msvcr90d.dll!abort()  Line 59 + 0x7 bytes	C<br /> 	msvcr90d.dll!_wassert(const wchar_t * expr=0x10026a4c, const wchar_t * filename=0x10026a08, unsigned int lineno=83)  Line 163	C<br />&gt;	allegro_audio-debug-5.1.dll!al_create_voice(unsigned int freq=44100, ALLEGRO_AUDIO_DEPTH depth=ALLEGRO_AUDIO_DEPTH_INT16, ALLEGRO_CHANNEL_CONF chan_conf=ALLEGRO_CHANNEL_CONF_2)  Line 83 + 0x5b bytes	C<br /> 	allegro_audio-debug-5.1.dll!create_default_mixer()  Line 87 + 0xf bytes	C<br /> 	allegro_audio-debug-5.1.dll!al_restore_default_mixer()  Line 303 + 0x5 bytes	C<br /> 	allegro_audio-debug-5.1.dll!al_reserve_samples(int reserve_samples=16)  Line 212 + 0x5 bytes	C<br /> 	my_audio_bug.exe!main()  Line 29 + 0xa bytes	C++<br /> 	my_audio_bug.exe!__tmainCRTStartup()  Line 586 + 0x19 bytes	C<br /> 	my_audio_bug.exe!mainCRTStartup()  Line 403	C<br /> 	kernel32.dll!_BaseProcessStart@4()  + 0x23 bytes
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (monacogp)</author>
		<pubDate>Sun, 30 Sep 2012 16:23:54 +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/611151/967157#target">monacogp</a> said:</div><div class="quote"><p>
But I noticed if I commented in the &quot;al_rest(0.001)&quot; line it would run fine.
</p></div></div><p>

Yes, there was a bug in the DirectSound driver. Fixed only on the 5.1 branch so far. I only tested in wine so thanks for testing it.</p><p>I&#39;ll see about the other bug, if I remember.
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (Peter Wang)</author>
		<pubDate>Sun, 30 Sep 2012 19:33:38 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><p>Much appreciated, thanks Peter <img src="http://www.allegro.cc/forums/smileys/smiley.gif" alt=":)" />
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (monacogp)</author>
		<pubDate>Mon, 01 Oct 2012 12:27:50 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><p>The assertion failure is probably because al_install_audio failed, but the test program continues anyway. I don&#39;t know why it would fail.
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (Peter Wang)</author>
		<pubDate>Mon, 01 Oct 2012 17:39:20 +0000</pubDate>
	</item>
</rss>
