簡體   English   中英

AVCaptureSession stopRunning() 神秘崩潰

[英]AVCaptureSession stopRunning() Mysterious Crash

最近我收到來自 firebase 的崩潰通知,這是消息:

[AVCaptureSession stopRunning] stopRunning may not be called between calls to beginConfiguration and commitConfiguration 

我瀏覽了我的代碼,最奇怪的部分是我從不打電話,也沒有提到beginConfiguration()commitConfiguration()

在我的CameraManager class 中,這是觸發崩潰的 function,它調用了 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只是一個串行調度隊列。 無論我嘗試什么,我都無法重現此崩潰。 嘗試拉菜單,推送通知,電話,模擬 memory 警告等......只是為了澄清,我的代碼中沒有一個地方調用beginConfigurationcommitConfiguration

我可以想象layer.session = nil將導致重新配置捕獲 session (因為刪除了與預覽層的連接)。 而且由於您正在調用stopRunning()異步,我想您可能會遇到在配置更改中間調用 stopRunning stopRunning() ) 的競爭條件。

我建議您嘗試使清理調用同步( queue.sync {... } )或將層清理也移動到async塊中。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM