最近我收到了有关 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
只是一个串行调度队列。无论我尝试什么,我都无法重现这次崩溃。
尝试拉菜单,推送通知,电话,模拟内存警告等......
只是为了澄清,我的代码中没有一个地方调用
beginConfiguration
和 commitConfiguration
.
最佳答案
我可以想象 layer.session = nil
将导致重新配置捕获 session (因为与预览层的连接已被删除)。既然你打电话 stopRunning()
异步,我想你可能会遇到竞争条件 stopRunning()
在配置更改的中间被调用。
我建议您尝试使清理调用同步( queue.sync { ... }
)或将层清理移动到 async
块。
关于ios - AVCaptureSession stopRunning() 神秘崩溃,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/67810724/