我正在使用WebRTC及其使用AVCaptureSession。它运行良好几次,但有一段时间它会因此异常而崩溃。
断言失败:(_ internal-> figCaptureSession == NULL),函数 - [AVCaptureVideoPreviewLayer attachToFigCaptureSession:],file /BuildRoot/Library/Caches/com.apple.xbs/Sources/EmbeddedAVFoundation/EmbeddedAVFoundation-1187.37.2.1/Aspen /AVCaptureVideoPreviewLayer.m
答案 0 :(得分:1)
我最近也遇到了这个问题。在我的代码中,我保留了AVCaptureOutput的实例并添加和删除了它。尝试将同一AVCaptureOutput实例再次添加到同一捕获会话时,出现此错误。
这是我解决的方法:
private var _captureOutput: AVCaptureOutput?
var captureOutput: AVCaptureOutput {
guard let captureOutput = _captureOutput else {
let photoOutput = AVCapturePhotoOutput()
photoOutput.isHighResolutionCaptureEnabled = true
_captureOutput = photoOutput
return photoOutput
}
return captureOutput
}
在需要时将实例初始化一次,并在删除时将其无效。
captureSession.outputs.forEach { [weak self] output in
self?.captureSession.removeOutput(output)
self?._captureOutput = nil
}
答案 1 :(得分:0)
在使用 RTCCameraPreviewView 实例之前,您必须取消它的 captureSession 并且断言将消失。遇到同样的问题。