matthewreagan / Starling

Simple low-latency audio library for iOS + macOS
Other
76 stars 9 forks source link

Unhandled Objective-C exception in `StarlingAudioPlayer.play(_:identifier:)` #7

Closed agurtovoy closed 1 year ago

agurtovoy commented 1 year ago

We've ran into a crash in Starling due to an unhandled Objective-C exception originating within AVFAudio framework:

Last Exception Backtrace:
0   CoreFoundation                  0x1a1dade88 __exceptionPreprocess + 164 (NSException.m:202)
1   libobjc.A.dylib                 0x19b0d78d8 objc_exception_throw + 60 (objc-exception.mm:356)
2   CoreFoundation                  0x1a1f1a814 +[NSException raise:format:arguments:] + 96 (NSException.m:0)
3   AVFAudio                        0x1b87314a4 AVAE_RaiseException(NSString*, ...) + 52 (AVAEInternal.h:69)
4   AVFAudio                        0x1b880dc54 AVAudioPlayerNodeImpl::StartImpl(AVAudioTime*) + 2876 (AVAudioPlayerNode.mm:660)
5   AVFAudio                        0x1b8731994 AVAudioNodeImplBase::Start(AVAudioTime*) + 64 (AVAudioNodeImpl.h:162)
6   AVFAudio                        0x1b880a794 -[AVAudioPlayerNode play] + 68 (AVAudioPlayerNode.mm:1138)
7   xxxxxxxxxxxxxx                  0x105127c70 StarlingAudioPlayer.play(_:identifier:) + 284 (Starling.swift:300)
8   xxxxxxxxxxxxxx                  0x10512712c performPlaybackOnFirstAvailablePlayer #1 () in Starling.performSoundPlayback(_:allowOverlap:) + 764 (Starling.swift:139)
9   xxxxxxxxxxxxxx                  0x105126e1c Starling.performSoundPlayback(_:allowOverlap:) + 832 (Starling.swift:0)
10  xxxxxxxxxxxxxx                  0x105128fec closure #1 in Starling.play(_:allowOverlap:) + 60 (Starling.swift:106)
11  xxxxxxxxxxxxxx                  0x105128fec partial apply for closure #1 in Starling.play(_:allowOverlap:) + 96 (<compiler-generated>:0)
12  xxxxxxxxxxxxxx                  0x105126428 thunk for @escaping @callee_guaranteed () -> () + 28 (<compiler-generated>:0)
13  libdispatch.dylib               0x1a937c4b4 _dispatch_call_block_and_release + 32 (init.c:1518)
14  libdispatch.dylib               0x1a937dfdc _dispatch_client_callout + 20 (object.m:560)
15  libdispatch.dylib               0x1a938fb8c _dispatch_root_queue_drain + 684 (inline_internal.h:2632)
16  libdispatch.dylib               0x1a9390284 _dispatch_worker_thread2 + 164 (queue.c:7052)
17  libsystem_pthread.dylib         0x1eee07dbc _pthread_wqthread + 228 (pthread.c:2631)
18  libsystem_pthread.dylib         0x1eee07b98 start_wqthread + 8 (:-1)

I was going to submit a PR wrapping node.play() call in ExceptionCatcher.catch, but realized that right now Starling doesn't have any external dependencies, and going down this route will introduce one.

@matthewreagan Would that be okay, or would you prefer a different approach?

agurtovoy commented 1 year ago

@matthewreagan We've been using our fork with the proposed fix (wrapping node.play() call in ExceptionCatcher.catch) for about two months now, and haven't experienced a crash since. Would you object to merging #8?

matthewreagan commented 1 year ago

@agurtovoy Will have it merged shortly, thank you for filing the issue & submitting the PR.