Using Allegro 5.0.5 running on Win XP, Directx9.0c I'm encountering an intermittent lockup when cleaning up audio.
Under Win7, I haven't encountered the bug at all.
If I destroy the mixer before destroying my voice, sometimes the program will lock at al_destroy_mixer.
If I destroy the voice first, it will hang on al_detach_voice(voice).
Once in a while it will get passed al_destroy_voice, al_destroy_mixer() and then hang on al_uninstall_audio().
This may be a huge assumption, but will al_destroy_mixer detach any attached voices before it is cleaned up? Will al_uninstall_audio() also attempt to do the same thing? WHAT IS THE PROPER ORDER?
When I say intermittent, I mean sometimes it will run/exit fine 20 times in a row (just loading main screen, exiting) and then randomly crash. Only thing I can do to reproduce it is to keep running/exiting until it happens. Code:blocks debugger doesnt appear to even catch that the app is hung up?
I can't really post complete code due to the size of the project and the resources involved. Just wanted to know if anyone else has had intermittent issues with cleaning up audio, and if so, what might I be doing wrong?
In that code, I am setting the streams to stop regardless of their state since if al_get_audio_stream_playing(stream) was returning false even though the stream WAS playing. Curious...
I generally don't post threads, preferring to smash my head against the wall and look at other forum posts until I've fixed the issue but I've searched high and low for similar issues and of the two threads I've seen, both seem to be unanswered.
Help me Obi Wan Allegro.cc... you're my only hope!
Edit: Debug did catch a crash finally...
#0 00000000 0x00448574 in _dsound_stop_voice() (??:??)
#1 00000000 0x00442f84 in al_detach_voice() (??:??)
#2 00000000 0x004467bf in _al_kcm_destroy_sample() (??:??)
#3 00000000 0x004445d6 in al_destroy_mixer() (??:??)
#4 00000000 0x00442930 in _al_kcm_shutdown_default_mixer() (??:??)
#5 00000000 0x00441e28 in al_uninstall_audio() (??:??)
#6 00000000 0x00467d1d in _al_run_exit_funcs() (??:??)
#7 00000000 0x00462ee8 in al_uninstall_system() (??:??)
#8 77C39E24 msvcrt!_initterm() (C:\WINNT\system32\msvcrt.dll:??)
#9 77C39EC5 msvcrt!_cexit() (C:\WINNT\system32\msvcrt.dll:??)
#10 00000000 0x00000000 in ??() (??:??)
EDIT - Updated Code:
Rather than crashing on al_detach_voice(); this code generally crashes on al_detach_mixer() unless I check al_get_mixer_attached(mixer). If I check, it seems to be false, and thus doesnt detach and it will crash on al_destroy_mixer()
I can't see anything in allegro.log that appears to be of relevance...
Tearing my hair out of my skull now... Why is it so random? Why do I have to run it 20-30 times before it'll happen? Then sometimes it'll happen as soon as I build and run once....
Could you try running this with a) 5.0.7 and b) with debug symbols turned on (so we see the lines in the backtrace)?
Anyway, the order you're doing things seems to be right, as this is the order Allegro uses for its default mixer:
al_destroy_mixer(allegro_mixer); al_destroy_voice(allegro_voice);
Linking to 5.0.7 now... Same issue.
Not sure why the debug trace shows up as allegro-5.0.x?
#0 0045002C _dsound_stop_voice(voice=0x1b130c0) (D:\Libraries\build\allegro\src\allegro-5.0.x\allegro-5.0.x\addons\audio\dsound.cpp:460)
#1 0044545A al_detach_voice(voice=0x1b130c0) (D:\Libraries\build\allegro\src\allegro-5.0.x\allegro-5.0.x\addons\audio\kcm_voice.c:376)
#2 0044A5C3 _al_kcm_detach_from_parent(spl=0x1b13738) (D:\Libraries\build\allegro\src\allegro-5.0.x\allegro-5.0.x\addons\audio\kcm_instance.c:116)
#3 0044A86D _al_kcm_destroy_sample(spl=0x1b13738, unregister=false) (D:\Libraries\build\allegro\src\allegro-5.0.x\allegro-5.0.x\addons\audio\kcm_instance.c:205)
#4 00448CDD al_destroy_mixer(mixer=0x1b13738) (D:\Libraries\build\allegro\src\allegro-5.0.x\allegro-5.0.x\addons\audio\kcm_mixer.c:943)
#5 00444585 _al_kcm_shutdown_default_mixer() (D:\Libraries\build\allegro\src\allegro-5.0.x\allegro-5.0.x\addons\audio\kcm_sample.c:476)
#6 0044358A al_uninstall_audio() (D:\Libraries\build\allegro\src\allegro-5.0.x\allegro-5.0.x\addons\audio\audio.c:323)
#7 004AF399 _al_run_exit_funcs() (D:\Libraries\build\allegro\src\allegro-5.0.x\allegro-5.0.x\src\allegro.c:136)
#8 004A8C5B al_uninstall_system() (D:\Libraries\build\allegro\src\allegro-5.0.x\allegro-5.0.x\src\system.c:310)
#9 77C39E24 msvcrt!_initterm() (C:\WINNT\system32\msvcrt.dll:??)
#10 77C39EC5 msvcrt!_cexit() (C:\WINNT\system32\msvcrt.dll:??)
#11 00000000 0x00000000 in ??() (??:??)
From dsound.cpp...
Line 460 is the last error... could this be failing because the buffer is already released? Shouldn't we check if its still valid before releasing? I've never compiled allegro on my own... not looking forward to the prospect of it, or the prospect of debugging directX having NO experience with it...
Also in dsound.cpp... Not sure if/when this is called (perhaps completely unrelated) Is the buffer intentionally not NULLed? Shouldnt it be?
Where do you get your voice/mixer from? It's not the allegro's default voice/mixer by any chance, is it?
Not sure what the "default mixer" would be? This is the initial setup
al_reserve_samples already will create a voice and mixer for you (and attach it), so you don't need the last three calls at all.
It still sounds like there is a bug in Allegro as creating a second voice is supposed to work. But a quick fix is likely to either not call al_reserve_samples (and don't use al_play_sample) or don't create a second voice.
Remarked out all the voice and mixer code, and attached my streams to the default mixer via al_get_default_mixer().
Seemed to work for a while (about thirty runs) but crashed again, this time on al_uninstall_audio(); Still crashed on the same line though....
#0 0044ED30 _dsound_stop_voice(voice=0x1b13868) (D:\Libraries\build\allegro\src\allegro-5.0.x\allegro-5.0.x\addons\audio\dsound.cpp:460)
#1 0044FDDA al_detach_voice(voice=0x1b13868) (D:\Libraries\build\allegro\src\allegro-5.0.x\allegro-5.0.x\addons\audio\kcm_voice.c:376)
#2 0044536F _al_kcm_detach_from_parent(spl=0x121c58e0) (D:\Libraries\build\allegro\src\allegro-5.0.x\allegro-5.0.x\addons\audio\kcm_instance.c:116)
#3 00445619 _al_kcm_destroy_sample(spl=0x121c58e0, unregister=false) (D:\Libraries\build\allegro\src\allegro-5.0.x\allegro-5.0.x\addons\audio\kcm_instance.c:205)
#4 0044B419 al_destroy_mixer(mixer=0x121c58e0) (D:\Libraries\build\allegro\src\allegro-5.0.x\allegro-5.0.x\addons\audio\kcm_mixer.c:943)
#5 00444751 _al_kcm_shutdown_default_mixer() (D:\Libraries\build\allegro\src\allegro-5.0.x\allegro-5.0.x\addons\audio\kcm_sample.c:476)
#6 00443756 al_uninstall_audio() (D:\Libraries\build\allegro\src\allegro-5.0.x\allegro-5.0.x\addons\audio\audio.c:323)
#7 004AF565 _al_run_exit_funcs() (D:\Libraries\build\allegro\src\allegro-5.0.x\allegro-5.0.x\src\allegro.c:136)
#8 004A8E27 al_uninstall_system() (D:\Libraries\build\allegro\src\allegro-5.0.x\allegro-5.0.x\src\system.c:310)
#9 77C39E24 msvcrt!_initterm() (C:\WINNT\system32\msvcrt.dll:??)
#10 77C39EC5 msvcrt!_cexit() (C:\WINNT\system32\msvcrt.dll:??)
#11 00000000 0x00000000 in ??() (??:??)
I have the most recent audio drivers for the chipset. Allegro.log doesn't appear to have any relevant information and I find that somewhat curious.
Perhaps I should note that the crash seems to occur even if I hadn't actually played any samples or streams yet.
Does this happen with the Allegro examples, like ex_audio_simple? I tried the examples on WinXP and they never crashed for me.