3

I use AudioEngine. In crash reports I see some random EXC_BREAKPOINT crashes with this stacktrace

Exception Type:  EXC_BREAKPOINT (SIGTRAP)  
Exception Codes: 0x0000000000000001, 0x00000001896df0e4  
Termination Signal: Trace/BPT trap: 5  
Termination Reason: Namespace SIGNAL, Code 0x5  
Terminating Process: exc handler [12467]  
Triggered by Thread:  15  

Thread 15 Crashed:  
0   libdispatch.dylib              0x00000001896df0e4 __DISPATCH_WAIT_FOR_QUEUE__ + 448 (queue.c:1619)  
1   libdispatch.dylib              0x00000001896dec74 _dispatch_sync_f_slow + 140 (queue.c:1732)  
2   libdispatch.dylib              0x00000001896dec74 _dispatch_sync_f_slow + 140 (queue.c:1732)  
3   AVFAudio                      0x00000001965b11a8 -[AVAudioEngine dealloc] + 308 (AVAudioEngine.mm:406)  
4   Foundation                    0x0000000189ce52ac -[NSConcreteNotification dealloc] + 68 (NSNotification.m:206)  
5   AVFAudio                      0x00000001965b7158 invocation function for block in AVAudioEngineImpl::IOUnitConfigurationChanged() + 292 (AVAudioEngine.mm:1215)  
6   libdispatch.dylib              0x00000001896de998 _dispatch_block_async_invoke2 + 104 (queue.c:525)  
7   libdispatch.dylib              0x00000001896fb184 _dispatch_client_callout + 16 (object.m:495)  
8   libdispatch.dylib              0x00000001896d4e8c _dispatch_continuation_pop$VARIANT$armv81 + 404 (inline_internal.h:2484)  
9   libdispatch.dylib              0x00000001896e502c _dispatch_source_invoke$VARIANT$armv81 + 1232 (source.c:568)  
10  libdispatch.dylib              0x00000001896d85e0 _dispatch_lane_serial_drain$VARIANT$armv81 + 260 (inline_internal.h:2525)  
11  libdispatch.dylib              0x00000001896d9128 _dispatch_lane_invoke$VARIANT$armv81 + 400 (queue.c:3863)  
12  libdispatch.dylib              0x00000001896e243c _dispatch_workloop_worker_thread + 576 (queue.c:6445)  
13  libsystem_pthread.dylib        0x000000018974ab88 _pthread_wqthread + 276 (pthread.c:2351)  
14  libsystem_pthread.dylib        0x000000018974d760 start_wqthread + 8

I can't reproduce this crash and stacktrace doesn't point to my code. Does anyone know what is cause of this crash, how this can be fixed and if it's even possible to fix? Thanks

Martin Vandzura
  • 3,047
  • 1
  • 31
  • 63

1 Answers1

0

According to the apple documentation of AVAudioEngineConfigurationChange, You must not release the engine during handling this notification.

Note The engine must not be deallocated from within the client's notification handler. Callback happens on an internal dispatch queue and can deadlock while trying to teardown the engine synchronously.

Though you didn't release at that time, It can be caused. AVAudioEngine in iOS 11 or 12 can be stucked to notify before, then you release engine later.

There's workaround. You have to re-use the audio engine rather than re-create.

Machavity
  • 30,841
  • 27
  • 92
  • 100
childc
  • 49
  • 3
  • 1
    This does seem like the obvious cause, but I’m also seeing this crash even though I dispatch to another queue before deallocating the engine. I don’t understand why that would deadlock. – Dan Halliday Sep 14 '21 at 09:31