EXC_BAD_ACCESS Sound error

Posts: 94
Joined: 2008.08
Post: #1
Im using the SoundEngine found in the crash lander sample app, I've used this successfully in one project already, but Ive come to implement it in a new project but Im getting a EXC_BAD_ACCESS error. This all runs fine in the simulator too.

Here is some of the code I use to init the sounds:

    NSBundle*                bundle = [NSBundle mainBundle];
    // Assume the listener is in the center at the start. The sound will pan as the position of the rocket changes.
    SoundEngine_SetListenerPosition(0.0, 0.0, kListenerDistance);
    // Load each of the four sounds used in the game.
    SoundEngine_LoadEffect([[bundle pathForResource:@"1" ofType:@"wav"] UTF8String], &_sounds[0]);

I've even tried using the same sound samples, with no success. When I type backtrace into the console I get this:

Program received signal:  â€œEXC_BAD_ACCESS”.
(gdb) backtrace
#0  std::_Rb_tree<unsigned long, std::pair<unsigned long const, SoundEngineEffect*>, std::_Select1st<std::pair<unsigned long const, SoundEngineEffect*> >, std::less<unsigned int>, std::allocator<std::pair<unsigned long const, SoundEngineEffect*> > >::find (this=0x80, __k=@0x2fffead8) at bits/stl_tree.h:1092
#1  0x00006dca in SoundEngineEffectMap::Get (this=0x80, inEffectToken=<value temporarily unavailable, due to optimizations>) at bits/stl_multimap.h:487
#2  0x00005d9e in OpenALObject::StartEffect () at /Users/usr/Desktop/IPHONEAPPS/db/SoundEngine.cpp:1359
#3  0x00005d9e in SoundEngine_StartEffect (inEffectID=<value temporarily unavailable, due to optimizations>) at /Users/usr/Desktop/IPHONEAPPS/db/SoundEngine.cpp:1534
#4  0x00005066 in -[EAGLView touchesBegan:withEvent:] (self=0x11d7d0, _cmd=<value temporarily unavailable, due to optimizations>, touches=0x137860, event=<value temporarily unavailable, due to optimizations>) at /Users/usr/Desktop/IPHONEAPPS/db/Classes/EAGLView.m:1112
#5  0x30a66c00 in -[UIWindow sendEvent:] ()
#6  0x30a57f18 in -[UIApplication sendEvent:] ()
#7  0x30a57250 in _UIApplicationHandleEvent ()
#8  0x315658cc in PurpleEventCallback ()
#9  0x3156811c in HeartbeatVBLCallback ()
#10 0x31e89900 in IOMobileFramebufferNotifyFunc ()
#11 0x30f57250 in IODispatchCalloutFromCFMessage ()
#12 0x3026ac76 in __CFMachPortPerform ()
#13 0x30269c78 in CFRunLoopRunSpecific ()
#14 0x30269326 in CFRunLoopRunInMode ()
#15 0x31563e60 in GSEventRunModal ()
#16 0x30a4feb8 in -[UIApplication _run] ()
#17 0x30a5961c in UIApplicationMain ()
#18 0x00002096 in main (argc=1, argv=0x2ffff540) at /Users/usr/Desktop/IPHONEAPPS/db/main.m:14db

Any ideas?

Quote this message in a reply
Posts: 94
Joined: 2008.08
Post: #2
I just scrapped my code from this and used the one from AnotherJake that he posted in another thread. Thanks for that BTW! Smile
Quote this message in a reply
Posts: 3,591
Joined: 2003.06
Post: #3
Heh. You're welcome. Smile
Quote this message in a reply
Posts: 94
Joined: 2008.08
Post: #4
Hmm, I still seem to be struggling with EXC_BAD_ACCESS errors with the new code. It doesnt seem to happen everytime, but often enough to be a problem It usually occurs when playing a second sound, but again it doesnt always happen.

This is how I'm using it:
                [song close];
                song = [[GBMusicTrack alloc] initWithPath:[[NSBundle mainBundle] pathForResource:@"whistleshort" ofType:@"wav"]];
                [song setRepeat:NO];
                [song play];

I'm closing the sound effect from what was previously played so I can play the new one. Im not sure if this is the best way, but this is the only way I could think to get it to work.

Any help is greatly appreciated! Thanks! Smile
Quote this message in a reply
Posts: 3,591
Joined: 2003.06
Post: #5
You have to release it before you play the next one, or bad things can happen.

I've noticed trouble from time to time with certain file formats. You might try re-exporting or re-encoding your audio file if it continues to be a problem. That issue is a bug with the OS as far as I can tell.

Lastly, for short sounds, you really should be using OpenAL (PITA to figure out, look at oalTouch or CrashLanding sample) or maybe AudioServicesPlaySystemSound (looks dead simple to use but I haven't tried it myself). Use GBMusicTrack for background music, because it was designed primarily to support playing compressed audio like mp3 and m4a, etc. And actually, I've personally been using AVAudioPlayer for background music since iPhone OS 2.2 because it offers the same capabilities as GBMusicTrack but is maintained by Apple.
Quote this message in a reply
Posts: 94
Joined: 2008.08
Post: #6
Thanks again!

I went back and tried the sound code form the CrashLanding example, and it worked fine. It must have been a seperate problem that I had the first time I used it. Smile
Quote this message in a reply
Post Reply 

Possibly Related Threads...
Thread: Author Replies: Views: Last Post
  Thread 4: EXC_BAD_ACCESS cmhubert 2 4,917 Sep 29, 2013 07:26 AM
Last Post: mawigator
  EXC_BAD_ACCESS Holyhoppsan 2 8,675 Aug 10, 2010 01:44 PM
Last Post: Holyhoppsan
  Why I recive EXC_BAD_ACCESS Rincha 11 9,950 Sep 16, 2009 01:55 PM
Last Post: maximile
  EXC_BAD_ACCESS in objc_msgSend saltwater 3 7,419 Sep 7, 2009 01:24 PM
Last Post: saltwater
  Random EXC_BAD_ACCESS bmpix 2 4,750 Feb 17, 2009 10:54 PM
Last Post: smallstepforman