Allegro.cc - Online Community

Allegro.cc Forums » Allegro Development » Occasional hang in al_detach_voice() when closing my application

This thread is locked; no one can reply to it. rss feed Print
Occasional hang in al_detach_voice() when closing my application
monacogp
Member #14,588
September 2012

Hi there!

Please can somebody help me! Finished my game, but I just have this one bug that I can't seem to fix. When I quit my game, my code does the following:

step 1 - Iterates through my list of sounds instances, stopping and destroying them.
step 2 - detaches the voice and the mixer
step 3 - destroys the voice and the mixer

Very occasionally my code hangs in al_detach_voice(). I'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.

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'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()):

ntdll.dll!_KiFastSystemCallRet@0()
ntdll.dll!_NtWaitForSingleObject@12() + 0xc bytes
kernel32.dll!_WaitForSingleObjectEx@12() + 0x8b bytes
kernel32.dll!_WaitForSingleObject@8() + 0x12 bytes
allegro-5.0.7-monolith-md-debug.dll!_al_thread_join(_AL_THREAD * thread=0x00fe3760) Line 80 C
allegro-5.0.7-monolith-md-debug.dll!al_join_thread(ALLEGRO_THREAD * thread=0x00fe3760, void * * ret_value=0x00000000) Line 201 + 0x9 bytes C
allegro-5.0.7-monolith-md-debug.dll!_dsound_stop_voice(ALLEGRO_VOICE * voice=0x00fe34d8) Line 456 + 0xe bytes C++
allegro-5.0.7-monolith-md-debug.dll!al_detach_voice(ALLEGRO_VOICE * voice=0x00fe34d8) Line 376 + 0xf bytes C
allegro-5.0.7-monolith-md-debug.dll!_al_kcm_detach_from_parent(ALLEGRO_SAMPLE_INSTANCE * spl=0x00fe3628) Line 116 + 0xf bytes C
allegro-5.0.7-monolith-md-debug.dll!al_detach_mixer(ALLEGRO_MIXER * mixer=0x00fe3628) Line 1257 + 0x9 bytes C
monaco79.exe!game_audio::uninit() Line 1857 + 0x12 bytes C++
monaco79.exe!main(int argc=1, const char * * argv=0x00ac62a8) Line 5697 C++
monaco79.exe!__tmainCRTStartup() Line 586 + 0x19 bytes C
monaco79.exe!mainCRTStartup() Line 403 C
kernel32.dll!_BaseProcessStart@4() + 0x23 bytes

I'm a bit concerned as the bug sounds exactly like this one entitled "(A5) random crash on al_detach_voice()" which doesn't look as if it was ever resolved:
http://www.allegro.cc/forums/thread/610569

Hope someone can help, many thanks if you read this far! :)

Ben

thebignic
Member #14,419
July 2012

Are you running this on Windows XP?

I only had my issue on XP. Never had it on Win 7 or iOS.

monacogp
Member #14,588
September 2012

Hi!

I've seen it hang On WinXP and Vista. I have a mate who's running my game on window 7 and he hasn't seen the hang yet..

Peter Wang
Member #23
April 2000

It's most likely a bug in Allegro. Can you make a small test case to reproduce the issue?

#SelectExpand
1#include <allegro5/allegro.h> 2#include <allegro5/allegro_audio.h> 3#include <allegro5/allegro_native_dialog.h> 4#include <stdio.h> 5 6int main(void) 7{ 8 ALLEGRO_TEXTLOG *log; 9 int i; 10 11 al_init(); 12 log = al_open_native_text_log("stress test", ALLEGRO_TEXTLOG_NO_CLOSE); 13 for (i = 0; ; i++) { 14 al_install_audio(); 15 al_reserve_samples(16); 16// al_rest(0.001); 17 al_uninstall_audio(); 18 al_append_native_text_log(log, "%d\n", i); 19 } 20 return 0; 21}

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.

monacogp
Member #14,588
September 2012

Sure thing, I'd be happy to give that a try :O) But please forgive me, but I'm having trouble working out how to build allegro :O(

You said you'd made some recent changes to the 5.1 branch. Where can I get those?

I found a link to some 5.1.3 unstable sources (here http://sourceforge.net/projects/alleg/files/allegro-unstable/), so I decided a good place to start would be to see if I could build these first.

I read the README_msvc.txt, I'm building with MSVC 2008, I've got the Microsoft SDKs v6.0A and v7.0A installed, I have the DirectX SDK (June 2010) installed.

I went to my c:\allergo_src\build directory and typed "cmake-gui ..", chose to do a vc9.0 (2008) build, clicked configure and got lots of warnings:-
Using VCINSTALLDIR: C:/Program Files/Microsoft Visual Studio 9.0/VC
Allowing MSVC to use SSE instructions
Could NOT find PkgConfig (missing: PKG_CONFIG_EXECUTABLE)
Could NOT find OpenAL (missing: OPENAL_LIBRARY OPENAL_INCLUDE_DIR)
Could NOT find FLAC (missing: FLAC_INCLUDE_DIR OGG_LIBRARY FLAC_LIBRARY)
WARNING: libFLAC not found or compile test failed, disabling support.
Could NOT find DUMB (missing: DUMB_INCLUDE_DIR DUMB_LIBRARY)
WARNING: libdumb not found or compile test failed, disabling support. <http://dumb.sourceforge.net/>
Could NOT find OGG (missing: OGG_INCLUDE_DIR OGG_LIBRARY)
WARNING: libvorbis not found or compile test failed, disabling support.
Could NOT find Freetype (missing: FREETYPE_LIBRARY FREETYPE_INCLUDE_DIRS)
WARNING: FreeType not found, disabling support.
Could NOT find PhysFS (missing: PHYSFS_LIBRARY PHYSFS_INCLUDE_DIR)
Could NOT find PHYSFS (missing: PHYSFS_LIBRARY PHYSFS_INCLUDE_DIR)
Could NOT find OGG (missing: OGG_INCLUDE_DIR OGG_LIBRARY)
Could NOT find OGG (missing: OGG_INCLUDE_DIR OGG_LIBRARY)
WARNING: allegro_video wanted but no supported backend found
Not building skater demo
Not building ex_color
Not building ex_depth_mask
Not building ex_physfs
Not building ex_video
Not building ex_font_justify
Not building ex_logo
Not building ex_projection
Not building ex_ttf
Not building ex_audio_chain
Not building ex_synth
Not building tests due to missing library. Have: allegro allegro_main allegro_image allegro_color allegro_font allegro_primitives
Configuring done

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

Many thanks,

Ben

Thomas Fjellstrom
Member #476
June 2000
avatar

monacogp said:

You said you'd made some recent changes to the 5.1 branch. Where can I get those?

You'll want to check out the files from the version control repo: http://www.liballeg.org/git.html

Quote:

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

You only need to care about those warnings if you want to use the addons that caused those warnings.

--
Thomas Fjellstrom - [website] - [email] - [Allegro Wiki] - [Allegro TODO]
"If you can't think of a better solution, don't try to make a better solution." -- weapon_S
"The less evidence we have for what we believe is certain, the more violently we defend beliefs against those who don't agree" -- https://twitter.com/neiltyson/status/592870205409353730

monacogp
Member #14,588
September 2012

Hi there! Thanks for the help, I managed to run Peter's test using the 5.1 source I git from http://www.liballeg.org/git.html :O)

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't crash/hang so I stopped it.

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't crash/hang within that time so I stopped it.

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.

I then decided to build the test code with my 5.0.7 Release sources. It hung immediately in al_unistall_audio(). But I noticed if I commented in the "al_rest(0.001)" line it would run fine.

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't click on anything during subsequent test runs.

msvcr90d.dll!_NMSG_WRITE(int rterrnum=10) Line 198 C
msvcr90d.dll!abort() Line 59 + 0x7 bytes C
msvcr90d.dll!_wassert(const wchar_t * expr=0x10026a4c, const wchar_t * filename=0x10026a08, unsigned int lineno=83) Line 163 C
> 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
allegro_audio-debug-5.1.dll!create_default_mixer() Line 87 + 0xf bytes C
allegro_audio-debug-5.1.dll!al_restore_default_mixer() Line 303 + 0x5 bytes C
allegro_audio-debug-5.1.dll!al_reserve_samples(int reserve_samples=16) Line 212 + 0x5 bytes C
my_audio_bug.exe!main() Line 29 + 0xa bytes C++
my_audio_bug.exe!__tmainCRTStartup() Line 586 + 0x19 bytes C
my_audio_bug.exe!mainCRTStartup() Line 403 C
kernel32.dll!_BaseProcessStart@4() + 0x23 bytes

Peter Wang
Member #23
April 2000

monacogp said:

But I noticed if I commented in the "al_rest(0.001)" line it would run fine.

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.

I'll see about the other bug, if I remember.

monacogp
Member #14,588
September 2012

Much appreciated, thanks Peter :)

Peter Wang
Member #23
April 2000

The assertion failure is probably because al_install_audio failed, but the test program continues anyway. I don't know why it would fail.

Go to: