ios - AVCaptureSession stopRunning() 神秘崩溃

标签 ios avfoundation avcapturesession

最近我收到了有关 firebase 崩溃的通知,这是消息:

[AVCaptureSession stopRunning] stopRunning may not be called between calls to beginConfiguration and commitConfiguration 
我浏览了我的代码,最奇怪的部分是我从不打电话,也没有提到 beginConfiguration()commitConfiguration() .
在我的 CameraManager class 这是触发崩溃的函数,它在 deinit 上调用:
  func stop() {
    guard isStarted else { return Log.w("CameraManager wasn't started") }
    queue.async {
        self.isStarted = false
        self.isCapturingFrame = false
        self.isCapturingCode = false
        self.session?.stopRunning()
        self.session = nil
        self.device = nil
    }
    notificationCenter.removeObserver(self, name: UIApplication.didBecomeActiveNotification, object: nil)
    layer.removeFromSuperlayer()
    layer.session = nil
}
queue只是一个串行调度队列。
无论我尝试什么,我都无法重现这次崩溃。
尝试拉菜单,推送通知,电话,模拟内存警告等......
只是为了澄清,我的代码中没有一个地方调用 beginConfigurationcommitConfiguration .

最佳答案

我可以想象 layer.session = nil将导致重新配置捕获 session (因为与预览层的连接已被删除)。既然你打电话 stopRunning()异步,我想你可能会遇到竞争条件 stopRunning()在配置更改的中间被调用。
我建议您尝试使清理调用同步( queue.sync { ... } )或将层清理移动到 async块。

关于ios - AVCaptureSession stopRunning() 神秘崩溃,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/67810724/

相关文章:

ios - 从同一 AVCaptureSession 拍摄视频和照片时应用程序崩溃?

ios - 无法检测全屏 AVPlayerViewController 转换

objective-c - AVCaptureVideoPreviewLayer 在简历上不显示任何内容

android - 具有 3D POI 的基于位置的增强现实框架(Android、iOS)?

ios - 提高 VNDetectHumanBodyPoseRequest 的 body 跟踪性能

ios - 如何使用 `AVCapturesession` 中的 `didOutputSampleBuffer` 播放音频缓冲区

ios - AVCaptureSession addOutput 第二次运行需要很长时间

ios - 如何在IOS 9(Swift)中将选定的联系人显示到下一个 View Controller 中

ios - 在 Swift MVC 中保存 TableView 数据

objective-c - 在越狱的 iPod touch 上使用 gdb 调试 iOS 应用程序 | Objective-C 符号