Hi,
I'm seeing a crash that I have no reproduction steps for and I'm wandering if I'm missing something in code. I want to check if headphones have been disconnected so I add a listener to audio route change.
AudioSessionAddPropertyListener(kAudioSessionProperty_AudioRouteChange, sessionPropertyListener, (__bridge void *)(self))
And than in the session property listener I check if I had headphones connected when kAudioSessionRouteChangeReason_OldDeviceUnavailable like so:
CFDictionaryRef previousRouteDescription = CFDictionaryGetValue(dict, kAudioSession_AudioRouteChangeKey_PreviousRouteDescription); CFArrayRef outputs = CFDictionaryGetValue(previousRouteDescription, kAudioSession_AudioRouteKey_Outputs);
CFIndex count = CFArrayGetCount(outputs); for (int i = 0; i < count; ++i) {
CFDictionaryRef outputDesc = CFArrayGetValueAtIndex(outputs, i);
CFStringRef outputRoute = CFDictionaryGetValue(outputDesc, kAudioSession_AudioRouteKey_Type);
if (kCFCompareEqualTo == CFStringCompare(outputRoute, kAudioSessionOutputRoute_Headphones, 0)) {
hadHeadphones = YES;
}
}
The crash I'm seeing is on CFStringCompare and it crashes with EXC_BAD_ACCESS and code: KERN_INVALID_ADDRESS at 0x0 That would mean that in some scenarios the outputRoute is NULL. I can do a proper check to be certain I don't run in any further issues but I'd like to understand when the error might happen in the code I wrote.
Regards, Alexandru |