OpenAL, Ogg/Vorbis music, and EXC_BAD_ACCESS

Apprentice
Posts: 15
Joined: 2005.12
Post: #1
There was a post with similar title, but its content was not relevant, so here is my problem. Porting a MMORPG to OS X. 3D part of game has been running fine, and I started playing with the sound/music component. Game uses OpenAL, and I am borrowing 10.4's framework. Sound effects have been working fine, and I moved on to ogg formatted music. I compiled my own Ogg and Vorbis frameworks. Occasionally now, the game will crash. Crashreport let me know that the offending thread was from OpenAL:
Code:
PID:    330
Thread: 2

Exception:  EXC_BAD_ACCESS (0x0001)
Codes:      KERN_PROTECTION_FAILURE (0x0002) at 0x00000011
...
Thread 2 Crashed:
0   com.apple.audio.OpenAL             0x9a7923c5 OALSource::ACComplexInputDataProc(OpaqueAudioConverter*, unsigned long*, AudioBufferList*, AudioStreamPacketDescription**, void*) + 301
1   ....audio.toolbox.AudioToolbox     0x93e79e81 AudioConverterChain::CallInputProc(unsigned long) + 189
2   ....audio.toolbox.AudioToolbox     0x93e79b1e AudioConverterChain::FillBufferFromInputProc(unsigned long*, unsigned long*, CABufferList*) + 84
3   ....audio.toolbox.AudioToolbox     0x93e79376 BufferedAudioConverter::GetInputBytes(unsigned long, unsigned long&, CABufferList const*&) + 234
4   ....audio.toolbox.AudioToolbox     0x93e79207 CBRConverter::RenderOutput(CABufferList*, unsigned long, unsigned long&, AudioStreamPacketDescription*) + 119
5   ....audio.toolbox.AudioToolbox     0x93e78f6b BufferedAudioConverter::FillBuffer(unsigned long&, AudioBufferList&, AudioStreamPacketDescription*) + 211
6   ....audio.toolbox.AudioToolbox     0x93e7932a BufferedAudioConverter::GetInputBytes(unsigned long, unsigned long&, CABufferList const*&) + 158
7   ....audio.toolbox.AudioToolbox     0x93e79207 CBRConverter::RenderOutput(CABufferList*, unsigned long, unsigned long&, AudioStreamPacketDescription*) + 119
8   ....audio.toolbox.AudioToolbox     0x93e78f6b BufferedAudioConverter::FillBuffer(unsigned long&, AudioBufferList&, AudioStreamPacketDescription*) + 211
9   ....audio.toolbox.AudioToolbox     0x93e790f9 AudioConverterChain::RenderOutput(CABufferList*, unsigned long, unsigned long&, AudioStreamPacketDescription*) + 93
10  ....audio.toolbox.AudioToolbox     0x93e78f6b BufferedAudioConverter::FillBuffer(unsigned long&, AudioBufferList&, AudioStreamPacketDescription*) + 211
11  ....audio.toolbox.AudioToolbox     0x93e78df8 AudioConverterFillComplexBuffer + 190
12  com.apple.audio.OpenAL             0x9a7928b6 OALSource::DoRender(AudioBufferList*) + 490
13  ...pple.audio.units.Components     0x70042ab8 AUPeakLimiterEntry + 7002
14  ...pple.audio.units.Components     0x70042c5e AUPeakLimiterEntry + 7424
15  ...pple.audio.units.Components     0x7004650a AUMixer3DEntry + 4750
...
Thread 2 crashed with i386 Thread State:
eax: 0x6c70636d    ebx: 0x93e79dd2 ecx:0x00000001 edx: 0x16b36cd4
edi: 0x16779b58    esi: 0x6167616e ebp:0xb02eeeb8 esp: 0xb02eee70
ss: 0x0000002f    efl: 0x00010206 eip:0x9a7923c5  cs: 0x00000027
ds: 0x0000002f     es: 0x0000002f  fs:0x00000000  gs: 0x00000037
...
I ran the game through gdb to see if I could find anything else:
Code:
Program received signal EXC_BAD_ACCESS, Could not access memory.
Reason: KERN_PROTECTION_FAILURE at address: 0x00000011
[Switching to process 597 thread 0x8d43]
0x9a7923c5 in OALSource::ACComplexInputDataProc ()
(gdb) bt
#0  0x9a7923c5 in OALSource::ACComplexInputDataProc ()
#1  0x93e79e81 in AudioConverterChain::CallInputProc ()
#2  0x93e79b1e in AudioConverterChain::FillBufferFromInputProc ()
#3  0x93e79376 in BufferedAudioConverter::GetInputBytes ()
#4  0x93e79207 in CBRConverter::RenderOutput ()
#5  0x93e78f6b in BufferedAudioConverter::FillBuffer ()
#6  0x93e7932a in BufferedAudioConverter::GetInputBytes ()
#7  0x93e79207 in CBRConverter::RenderOutput ()
#8  0x93e78f6b in BufferedAudioConverter::FillBuffer ()
#9  0x93e790f9 in AudioConverterChain::RenderOutput ()
#10 0x93e78f6b in BufferedAudioConverter::FillBuffer ()
#11 0x93e78df8 in AudioConverterFillComplexBuffer ()
#12 0x9a7928b6 in OALSource::DoRender ()
...looks about the same. Has anyone seen anything similar, and/or does anyone have advice? I tried a different *.ogg file and it crashes at the same place after a while. Note, the crash is not immediate when playing the *.ogg. The code replays the song numerous times (as it should) before crashing.

This is all on a MacBook Pro.
Quote this message in a reply
Luminary
Posts: 5,143
Joined: 2002.04
Post: #2
It's a bug in the OpenAL that comes with 10.4. It's fixed in the latest development branch, but you'll need to compile it from source.

If you want to avoid the inconvenience, http://onesadcookie.com/svn/repos/Thirdparty knows how to build an OpenAL framework that works on ppc/10.3.9+ and i386/10.4.0+ and includes a source snapshot with this bug fixed, or you can just download Outnumbered from http://onesadcookie.com/Software and pull the precompiled framework out of the application bundle.
Quote this message in a reply
Apprentice
Posts: 15
Joined: 2005.12
Post: #3
I compiled that snapshot without issue. I replaced the OpenAL.framework from /System/Library/Frameworks since my program wants to link against that one. Is there a way to change the search order so that /Library/Frameworks or ~/Library/Frameworks is searched first?

Anyhow, now I just get static from the game rather than music (although I did not notice any crashing).
Quote this message in a reply
Luminary
Posts: 5,143
Joined: 2002.04
Post: #4
That framework is set up to live inside your application bundle. You should not ever edit /System under any circumstances. You'll need to make sure your application is linked against the new AL, not the system one.

Odd that you're getting static -- It certainly works for me in Outnumbered, and I haven't had any bug reports about it.
Quote this message in a reply
Apprentice
Posts: 15
Joined: 2005.12
Post: #5
Yeah, I know it is meant to live in the bundle. I changed the order of the Framework Search Paths to avoid the System OpenAL.framework. While a separate OpenAL problem seems to be fixed (relating to buffers), I still get static/snow when trying to play a *.ogg. What audio formats did you use in your game?
Quote this message in a reply
Luminary
Posts: 5,143
Joined: 2002.04
Post: #6
It's playing Oggs.
Quote this message in a reply
Apprentice
Posts: 15
Joined: 2005.12
Post: #7
Hmmm.... I tried to use your framework too (from your game), but I still got static. This begs the question, what is different between your snapshot and the version that comes with 10.4.5? The OS X version will play the music fine, but it eventually crashes with the previously mentioned errors.

*.wav files are fine.
Quote this message in a reply
Luminary
Posts: 5,143
Joined: 2002.04
Post: #8
Sounds like you have a broken ogg/vorbis library, or you're loading your ogg files with the wrong endianness...

The "Thirdparty" link above builds ogg & vorbis too if you're interested Smile
Quote this message in a reply
Apprentice
Posts: 15
Joined: 2005.12
Post: #9
Quote:Sounds like you have a broken ogg/vorbis library
Maybe, since I compiled my own frameworks since i386 versions were not available. However, *.ogg music will play using built-in OS X OpenAL and my ogg/vorbis libraries..it is just that OpenAL will crash after playing looping music for a while.

This may be a dumb question, but do your scripts do anything more than the xcode projects included in libogg and libvorbis? Well, other than not actually producing the framework architecture/package?

BTW, the OpenAL snapshot did not fix that other problem that I briefly mentioned. Ugg, this is a pain. Thank you for your patience.
Quote this message in a reply
Apprentice
Posts: 15
Joined: 2005.12
Post: #10
OSC, when is that openal snapshot from?

[edit] well, I grabbed the latest subversion from openal.org, compiled it, and ogg sound seems to be playing fine. Now I have to wait to see if it crashes after a while.
Quote this message in a reply
Luminary
Posts: 5,143
Joined: 2002.04
Post: #11
That snapshot was off the 1.1 development branch. I haven't checked out the state of the repository recently, so perhaps the 1.1 branch has been merged onto the trunk, or perhaps the bug was fixed for 1.0... but neither of those were the case when I made the snapshot Smile
Quote this message in a reply
Post Reply 

Possibly Related Threads...
Thread: Author Replies: Views: Last Post
  EXC_BAD_ACCESS with gluBuild2DMipmaps Marjock 3 3,541 Aug 5, 2007 01:38 AM
Last Post: Marjock
  open AL crash with EXC_BAD_ACCESS carlo 9 4,284 Apr 12, 2006 09:23 PM
Last Post: Sabrina
  Stumped by EXC_BAD_ACCESS maaaaark 8 4,246 Mar 24, 2005 11:19 PM
Last Post: arekkusu
  problems with ogg/vorbis frameworks johnMG 5 4,791 Mar 11, 2005 07:22 PM
Last Post: johnMG
  glGenTextures and EXC_BAD_ACCESS BobbyWatson 1 4,823 Aug 31, 2002 01:48 PM
Last Post: BobbyWatson