线程和动画控制器解雇崩溃

时间:2017-03-01 10:22:54

标签: ios swift uiviewcontroller swift3 uiviewanimation

我一直在摸索这个问题一段时间了:

设置

我的情况是我有一个导航控制器(A) - >控制器(B)。

(B)从(A)推出如下:

func presentPhotoController() {

    let photoController = PhotoCaptureController()
    let navController = UINavigationController(rootViewController: photoController)

    self.present(navController, animated: true, completion: nil)
}

控制器(B)是相机屏幕(具有AVCaptureSession)。当按下(B)按下按钮时,按钮允许返回(A)。

问题

当(B)调用self.dismiss(animated: true, completion: nil)时,一切正常。

当(B)调用self.dismiss(animated: false, completion: nil)时,我确实需要它,我在调度队列中遇到了令人讨厌的崩溃:

override func observeValue(forKeyPath keyPath: String?, of object: Any?, change: [NSKeyValueChangeKey : Any]?, context: UnsafeMutableRawPointer?) {
    if context == &sessionRunningObserveContext {
        let newValue = change?[.newKey] as AnyObject?
        guard let isSessionRunning = newValue?.boolValue else { return }

        DispatchQueue.main.async { [unowned self] in
            // Only enable the ability to change camera if the device has more than one camera.
            self.cameraButton.isEnabled = isSessionRunning && (self.videoDeviceDiscoverySession.uniqueDevicePositionsCount()) > 1
            self.photoButton.isEnabled = isSessionRunning
            self.flashButton.isEnabled = isSessionRunning
        }
    }
    else {
        super.observeValue(forKeyPath: keyPath, of: object, change: change, context: context)
    }
}

以下是堆栈跟踪:

libswiftCore.dylib`_swift_abortRetainUnowned:
0x100dc5598 <+0>:  adr    x8, #571352               ; gCRAnnotations
0x100dc559c <+4>:  nop    
0x100dc55a0 <+8>:  adr    x9, #182131               ; "attempted to retain deallocated object"
0x100dc55a4 <+12>: nop    
0x100dc55a8 <+16>: str    x9, [x8, #8]
->  0x100dc55ac <+20>: brk    #0x1

libswiftCore.dylib`swift_unknownUnownedLoadStrong:
0x100dd4b04 <+0>:  stp    x20, x19, [sp, #-32]!
0x100dd4b08 <+4>:  stp    x29, x30, [sp, #16]
0x100dd4b0c <+8>:  add    x29, sp, #16              ; =16 
0x100dd4b10 <+12>: ldr    x19, [x0]
0x100dd4b14 <+16>: cbz    x19, 0x100dd4b28          ; <+36>
0x100dd4b18 <+20>: tbnz   w19, #0, 0x100dd4b30      ; <+44>
0x100dd4b1c <+24>: mov    x0, x19
0x100dd4b20 <+28>: bl     0x100dc555c               ; swift_unownedRetainStrong
0x100dd4b24 <+32>: b      0x100dd4b40               ; <+60>
0x100dd4b28 <+36>: movz   x19, #0
0x100dd4b2c <+40>: b      0x100dd4b40               ; <+60>
0x100dd4b30 <+44>: and    x0, x19, #0xfffffffffffffffe
0x100dd4b34 <+48>: bl     0x100de014c               ; symbol stub for: objc_loadWeakRetained
0x100dd4b38 <+52>: mov    x19, x0
0x100dd4b3c <+56>: cbz    x19, 0x100dd4b50          ; <+76>
0x100dd4b40 <+60>: mov    x0, x19
0x100dd4b44 <+64>: ldp    x29, x30, [sp, #16]
0x100dd4b48 <+68>: ldp    x20, x19, [sp], #32
0x100dd4b4c <+72>: ret    
0x100dd4b50 <+76>: movz   x0, #0
0x100dd4b54 <+80>: bl     0x100dc5598               ;    _swift_abortRetainUnowned

解决方案?

作为Swift的新手,上面对我来说感觉非常神秘。如果我猜对了,似乎这次崩溃是因为试图保留一个解除分配的对象?我不明白为什么控制器解雇动画会改变任何东西。

有人可以帮我弄清楚究竟发生了什么吗?

非常感谢提前。

0 个答案:

没有答案