Reputation: 307
I am using WebRTC
and its using AVCaptureSession
. It works fine a few times but sometimes its getting crashed with this Exception.
Assertion failed: (_internal->figCaptureSession == NULL), function -[AVCaptureVideoPreviewLayer attachToFigCaptureSession:], file /BuildRoot/Library/Caches/com.apple.xbs/Sources/EmbeddedAVFoundation/EmbeddedAVFoundation-1187.37.2.1/Aspen/AVCaptureVideoPreviewLayer.m
Upvotes: 12
Views: 938
Reputation: 11
Before using instance of RTCCameraPreviewView you have to nill'ify its captureSession and assert will go away. Faced same issue.
Upvotes: 1
Reputation: 73
I recently had this problem aswell. In my code i kept an instance of AVCaptureOutput and added and removed it. When trying to add the same AVCaptureOutput instance to the same capture session again, this error appeared.
This is how i solved it:
private var _captureOutput: AVCaptureOutput?
var captureOutput: AVCaptureOutput {
guard let captureOutput = _captureOutput else {
let photoOutput = AVCapturePhotoOutput()
photoOutput.isHighResolutionCaptureEnabled = true
_captureOutput = photoOutput
return photoOutput
}
return captureOutput
}
Initialize the instance once when needed and when removed, also nullify it.
captureSession.outputs.forEach { [weak self] output in
self?.captureSession.removeOutput(output)
self?._captureOutput = nil
}
Upvotes: 1