Hi,
We recently started using AVAudioEngine in our app, and are receiving reports of crashes in the wild, specifically:
com.apple.coreaudio.avfaudio
required condition is false: hwFormat
These crashes are occurring on all iOS versions, including the latest (10.0.2 14A456).
The crashes are always on a background thread. Here is one example stack trace:
(CoreFoundation + 0x0012f1c0 ) __exceptionPreprocess
(libobjc.A.dylib + 0x00008558 ) objc_exception_throw
(CoreFoundation + 0x0012f090 ) +[NSException raise:format:arguments:]
(AVFAudio + 0x00016788 ) AVAE_RaiseException(NSString*, ...)
(AVFAudio + 0x0008f168 ) AVAudioIOUnit::_GetHWFormat(unsigned int, unsigned int*)
(AVFAudio + 0x0008ee64 ) ___ZN13AVAudioIOUnit22IOUnitPropertyListenerEPvP28OpaqueAudioComponentInstancejjj_block_invoke_2
(libdispatch.dylib + 0x000011fc ) _dispatch_call_block_and_release
(libdispatch.dylib + 0x000011bc ) _dispatch_client_callout
(libdispatch.dylib + 0x0000f440 ) _dispatch_queue_serial_drain
(libdispatch.dylib + 0x000049a4 ) _dispatch_queue_invoke
(libdispatch.dylib + 0x00011388 ) _dispatch_root_queue_drain
(libdispatch.dylib + 0x000110e8 ) _dispatch_worker_thread3
(libsystem_pthread.dylib + 0x000012c4 ) _pthread_wqthread
(libsystem_pthread.dylib + 0x00000db0 ) start_wqthread
When this crash occurs, the main thread is generally responding to an audio route change. Here is one example stack trace:
(libsystem_kernel.dylib + 0x0000116c ) mach_msg_trap
(libsystem_kernel.dylib + 0x00000fd8 ) mach_msg
(libdispatch.dylib + 0x0001cac0 ) _dispatch_mach_msg_send
(libdispatch.dylib + 0x0001c214 ) _dispatch_mach_send_drain
(libdispatch.dylib + 0x0001d414 ) _dispatch_mach_send_push_and_trydrain
(libdispatch.dylib + 0x000174a8 ) _dispatch_mach_send_msg
(libdispatch.dylib + 0x000175cc ) dispatch_mach_send_with_result
(libxpc.dylib + 0x00002c80 ) _xpc_connection_enqueue
(libxpc.dylib + 0x00003cf0 ) xpc_connection_send_message_with_reply
(MediaRemote + 0x00011edc ) MRMediaRemoteServiceGetPickedRouteHasVolumeControl
(MediaPlayer + 0x0009d57c ) -[MPAVRoutingController _pickableRoutesDidChangeNotification:]
(CoreFoundation + 0x000c9228 ) __CFNOTIFICATIONCENTER_IS_CALLING_OUT_TO_AN_OBSERVER__
(CoreFoundation + 0x000c892c ) _CFXRegistrationPost
(CoreFoundation + 0x000c86a8 ) ___CFXNotificationPost_block_invoke
(CoreFoundation + 0x00137b98 ) -[_CFXNotificationRegistrar find:object:observer:enumerator:]
(CoreFoundation + 0x0000abf0 ) _CFXNotificationPost
(Foundation + 0x000066b8 ) -[NSNotificationCenter postNotificationName:object:userInfo:]
(MediaServices + 0x00003100 ) -[MSVDistributedNotificationObserver _handleDistributedNotificationWithNotifyToken:]
(MediaServices + 0x00002f10 ) __78-[MSVDistributedNotificationObserver initWithDistributedName:localName:queue:]_block_invoke
(libsystem_notify.dylib + 0x00009ea4 ) ___notify_dispatch_local_notification_block_invoke
(libdispatch.dylib + 0x000011fc ) _dispatch_call_block_and_release
(libdispatch.dylib + 0x000011bc ) _dispatch_client_callout
(libdispatch.dylib + 0x00005d68 ) _dispatch_main_queue_callback_4CF
(CoreFoundation + 0x000dcf28 ) __CFRUNLOOP_IS_SERVICING_THE_MAIN_DISPATCH_QUEUE__
(CoreFoundation + 0x000dab14 ) __CFRunLoopRun
(CoreFoundation + 0x00009044 ) CFRunLoopRunSpecific
(GraphicsServices + 0x0000c194 ) GSEventRunModal
(UIKit + 0x0007b624 ) -[UIApplication _run]
(UIKit + 0x0007635c ) UIApplicationMain
This looks like the same issue as https://forums.developer.apple.com/message/36184#36184
One potential complication is that we are calling AVAudioEngine methods off of the main thread. My belief is that this is safe - but I can't find any official reference to confirm that it is. We find that AVAudioEngine method calls can block, which is why we moved the work off the main thread.
We are listening for audio engine configuration change notifications and handling them similarly to the AVAudioEngine sample code.
I have attempted to reproduce this issue locally by performing various actions in combination (receiving phone calls, suspending the app, plugging in or unplugging headphones, etc) with no luck.
Any thoughts on what conditions might be triggering this exception? Hopefully, I can at least narrow down a set of conditions to allow me to reproduce the crash in a controlled environment.
Thanks,
Rob