Crash AudioRecorderSessionPropertyListener

Can anyone please help me to interpret this crashed thread?


It's from an app that records and plays audio. From line 2 I understand that the crash happened during audio recording, but what happened during the recording that made it crash?


0 libobjc.A.dylib 0x000000018442c910 objc_msgSend + 16
1 AVFAudio 0x000000018ab9f87c AudioRecorderSessionPropertyListener(void*, unsigned int, unsigned int, void const*) + 148
2 AudioToolbox 0x0000000188ecfcc0 AudioSessionPropertyListeners::CallPropertyListenersImp(AudioSessionPropertyListeners const&, unsigned int, unsigned int, void const*) + 740
3 AudioToolbox 0x0000000188fc2a3c AudioSessionPropertyListeners::CallPropertyListeners(unsigned int, unsigned int, void const*) + 220
4 AudioToolbox 0x00000001890060d0 ProcessInterruptionListenerMessage(unsigned int, unsigned int, unsigned int) + 344
5 AudioToolbox 0x0000000189005dc0 HandleAudioSessionCFTypePropertyChangedMessage(unsigned int, unsigned int, void*, unsigned int) + 556
6 AudioToolbox 0x0000000189005328 ProcessDeferredMessage(unsigned int, __CFData const*, unsigned int, unsigned int) + 2028
7 AudioToolbox 0x000000018900484c ASCallbackReceiver_AudioSessionPingMessage + 580
8 AudioToolbox 0x0000000188ec02a8 _XAudioSessionPingMessage + 48
9 AudioToolbox 0x00000001891a7210 mshMIGPerform + 228
10 CoreFoundation 0x0000000185207ae8 __CFRUNLOOP_IS_CALLING_OUT_TO_A_SOURCE1_PERFORM_FUNCTION__ + 52
11 CoreFoundation 0x0000000185207230 __CFRunLoopDoSource1 + 436
12 CoreFoundation 0x0000000185204c80 __CFRunLoopRun + 2452
13 CoreFoundation 0x0000000185124da8 CFRunLoopRunSpecific + 548
14 AVFAudio 0x000000018ac0a424 GenericRunLoopThread::Entry(void*) + 160
15 AVFAudio 0x000000018ac34834 CAPThread::Entry(CAPThread*) + 84
16 libsystem_pthread.dylib 0x0000000184e85220 _pthread_body + 268
17 libsystem_pthread.dylib 0x0000000184e85110 _pthread_start + 288
18 libsystem_pthread.dylib 0x0000000184e83b10 thread_start + 0

Well, you crashed in objc_msgSend, which means a message was being sent to an object, and the object was presumably invalid. The most likely reason is a memory management error — the object has been deallocated.


I would look into places in your code where you expect a callback, and check you're handling the objects properly. For example, many callbacks have a 'context' parameter that is sometimes used to pass an object pointer, but the argument type is 'void*', which means the pointer isn't memory managed properly. Or, it could just indicated a buffer overflow in one of your audio buffers that wasn't as big as you said it was. That can have tragic side effects a long way from the point of the error.


Are there any message shown just above the backtraces? There might be a readable message about an invalid selector, or something like that, and there should be something that says what kind of crash signal this was (access violation, abort, etc).

Yes, the message shown is:


Exception Type: SIGSEGV
Exception Codes: SEGV_ACCERR at 0x900000010
Crashed Thread: 3

Application Specific Information:
objc_msgSend() selector name: respondsToSelector:


Does that give you a better understanding of the bug cause?

Accepted Answer

It provides a little more information. Given that it was trying to send a 'respondsToSelector:' message to an object at the time it crashed, it suggests that the object has been released and its memory returned to the free memory heap.


We don't know exactly why it's trying to send 'respondsToSelector:', but this is something that's typically done before messaging an optional delegate method (it has to find out if the delegate exists and implements that method).


So I upgrade my guess to say that you have a delegate object that isn't being kept alive. (Note that most 'delegate' properties are weak references, so setting a delegate doesn't ensure it will stay alive. You need to keep a strong reference somewhere, too.)


You can try turning on Zombies in your scheme's diagnostic tab. This will make your app run more slowly, which might cause other audio problems, but if you're lucky it will tell you which object is at fault. Also, if you're using a recent enough version of Xcode, turn on both the address sanitizer and thread sanitizer options if you can.

I think that was exactly the cause. The `AVAudioRecorder` is `unowned (unsafe)` but I assumed it was `weak`. So I created a weak reference for the delegate to make it safe.

Crash AudioRecorderSessionPropertyListener
 
 
Q