How Can I Solve An EXC_BAD_ACCESS That Occurs Within the AudioToolBox of IOS

I need help solving a problem where I experience an occasional EXC_BAD_ACCESS crash that occurs in the AudioToolBox (AVAudioSessionPropertyListener) . Most of them happened in background and it's not easy to reproduce the bug.

The following is the call trace:


Thread : Crashed: AVAudioSession Notify Thread
0  libobjc.A.dylib                0x18243dbd0 objc_msgSend + 16
1  libAVFAudio.dylib              0x188f333c8 LocalPlayerHandleCallback(AVAudioPlayer*, unsigned int, unsigned long, void const*) + 368
2  libAVFAudio.dylib              0x188f37098 AVAudioPlayerCpp::sessionPropertyListener(unsigned int, unsigned int, void const*) + 360
3  AudioToolbox                   0x1852d27c0 AudioSessionPropertyListeners::CallPropertyListenersImp(unsigned int, unsigned int, void const*) + 352
4  AudioToolbox                   0x1852d2584 AudioSessionPropertyListeners::CallPropertyListeners(unsigned int, unsigned int, void const*) + 280
5  AudioToolbox                   0x1852d1a60 ProcessDeferredMessage(__CFData const*, unsigned int, unsigned int) + 512
6  AudioToolbox                   0x1852d14e4 ASCallbackReceiver_AudioSessionPingMessage + 408
7  AudioToolbox                   0x1853cc5e8 _XAudioSessionPingMessage + 44
8  AudioToolbox                   0x1851c5900 mshMIGPerform + 248
9  CoreFoundation                 0x182d75634 __CFRUNLOOP_IS_CALLING_OUT_TO_A_SOURCE1_PERFORM_FUNCTION__ + 56
10 CoreFoundation                 0x182d74d6c __CFRunLoopDoSource1 + 436
11 CoreFoundation                 0x182d72ac4 __CFRunLoopRun + 1800
12 CoreFoundation                 0x182ca1680 CFRunLoopRunSpecific + 384
13 libAVFAudio.dylib              0x188f69834 GenericRunLoopThread::Entry(void*) + 164
14 libAVFAudio.dylib              0x188f3e3a8 CAPThread::Entry(CAPThread*) + 84
15 libsystem_pthread.dylib        0x182a27b28 _pthread_body + 156
16 libsystem_pthread.dylib        0x182a27a8c _pthread_body + 154
17 libsystem_pthread.dylib        0x182a25028 thread_start + 4


Does anybody have an idea of what could possibly be happening or what should I do to solve it? Thanks!

Answered by theanalogkid in 121915022

This is an objc_msgSend crasher and there's a number of things you can do to attempt to track down what's going on. The first place to look is the most likely case - a message being sent to an object that no longer exists. As it looks like there's some audio session property handling going on, are you using an AVAudioPlayerDelegate, if so, is that object going away before you expect it to. How about AVAudioPlayer itself, is it possible it's being released during playback...these are the first things to check. You can also use NSZombieEnabled, and searching for objc_msgSend will yield some very helpful blogs and links discussing how to figure out what exactly is wrong. If you've exhausted all possibilities and have a simple test case the replicates the problem on the off chance this is our bug, please file a bug report so we can take a look.


Some References:

https://developer.apple.com/library/ios/technotes/tn2239/_index.html

https://developer.apple.com/library/ios/documentation/DeveloperTools/Conceptual/InstrumentsUserGuide/EradicatingZombies.html

Does your app make any AVAudioSession calls? Did you check all error returns? Does your app release any objects making audio calls?

Yes but only setCategory and setActive get called by [AVAudioSession sharedInstance]. Should I check error returns? What should I do if get any error return?

Accepted Answer

This is an objc_msgSend crasher and there's a number of things you can do to attempt to track down what's going on. The first place to look is the most likely case - a message being sent to an object that no longer exists. As it looks like there's some audio session property handling going on, are you using an AVAudioPlayerDelegate, if so, is that object going away before you expect it to. How about AVAudioPlayer itself, is it possible it's being released during playback...these are the first things to check. You can also use NSZombieEnabled, and searching for objc_msgSend will yield some very helpful blogs and links discussing how to figure out what exactly is wrong. If you've exhausted all possibilities and have a simple test case the replicates the problem on the off chance this is our bug, please file a bug report so we can take a look.


Some References:

https://developer.apple.com/library/ios/technotes/tn2239/_index.html

https://developer.apple.com/library/ios/documentation/DeveloperTools/Conceptual/InstrumentsUserGuide/EradicatingZombies.html

I found that all crashes happened after receiving some AVAudioSession notifications:


JQSportReporter | -[JQSportReporter aVAudioSessionInterruptted:] @ 491 | AudioSessionInterruptted: {
    AVAudioSessionInterruptionTypeKey = 1;
}
JQSportReporter | -[JQSportReporter aVAudioSessionRouteChanged:] @ 495 | AudioSessionRouteChanged: {
    AVAudioSessionRouteChangePreviousRouteKey = "<AVAudioSessionRouteDescription: 0x1369c9ce0, \ninputs = (null); \noutputs = (\n    \"<AVAudioSessionPortDescription: 0x13a0db960, type = Speaker; name = \\U626c\\U58f0\\U5668; UID = Speaker; selectedDataSource = (null)>\"\n)>";
    AVAudioSessionRouteChangeReasonKey = 3;
}, currentRoute is: <AVAudioSessionRouteDescription: 0x1357ebba0,
inputs = (null);
outputs = (
    "<AVAudioSessionPortDescription: 0x135504050, type = Speaker; name = \U626c\U58f0\U5668; UID = Speaker; selectedDataSource = (null)>"
)>
JQSportReporter | -[JQSportReporter aVAudioSessionInterruptted:] @ 491 | AudioSessionInterruptted: {
    AVAudioSessionInterruptionOptionKey = 1;
    AVAudioSessionInterruptionTypeKey = 0;
}
AppDelegate | -[AppDelegate applicationDidBecomeActive:] @ 267 | applicationDidBecomeActive
JQSportTask | -[JQConfigurationManager prepare] @ 139 | Initial Configurations


According to the logs I'm sure the app get relaunching after receiving those notifications.


Could you please help me understand what is the problem?

How Can I Solve An EXC_BAD_ACCESS That Occurs Within the AudioToolBox of IOS
 
 
Q