shogo4405 / HaishinKit.swift

Camera and Microphone streaming library via RTMP and SRT for iOS, macOS, tvOS and visionOS.

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

AVCaptureSession startRunning crash

leo150 opened this issue · comments

Describe the bug

I'm getting a lot of crashes in Crashlytics with the following error:

Fatal Exception: NSGenericException
-[AVCaptureSession startRunning] startRunning may not be called between calls to beginConfiguration and commitConfiguration

Frame Image Call
0 CoreFoundation __exceptionPreprocess
1 libobjc.A.dylib objc_exception_throw
2 AVFCapture -[AVCaptureSession startRunning]
3 HaishinKit IOMixer.startCaptureSession()
4 HaishinKit thunk for @escaping @callee_guaranteed () -> ()
5 libdispatch.dylib _dispatch_call_block_and_release
6 libdispatch.dylib _dispatch_client_callout
7 libdispatch.dylib _dispatch_lane_serial_drain
8 libdispatch.dylib _dispatch_lane_invoke
9 libdispatch.dylib _dispatch_workloop_worker_thread
10 libsystem_pthread.dylib _pthread_wqthread
11 libsystem_pthread.dylib start_wqthread

This started happening after updating from 1.4.5 to 1.5.2.

Looks like the crash happens during the queue block invocation. I checked every beginConfiguration() call in the project and all of them are wrapped by lockQueue. beginConfiguration also isn't called externally. Maybe it's called somewhere where I didn't notice without a queue? Could you please help me to figure out the source of this crash?

To Reproduce

I don't have steps to reproduce it yet.

Expected behavior

No crash

Version

1.5.2

Smartphone info.

Happens on all kind of devices with iOS 15-16-17

Additional context

No response

Screenshots

No response

Relevant log output

No response

It appears that the main thread and the netStream.lockQueue thread are mixed, causing a race condition.

private func willEnterForeground(_ notification: Notification) {
resumeCaptureSessionIfNeeded()
if #available(iOS 16, *) {
guard !session.isMultitaskingCameraAccessEnabled else {
return
}
}
videoIO.capture.attachSession(session)
videoIO.multiCamCapture.attachSession(session)
}
#endif