Проблема времени выполнения в проекте Apple ARKit Face Recognition (ARKitFaceExample) - PullRequest
3 голосов
/ 26 апреля 2019

Apple выпустила это:

https://developer.apple.com/documentation/arkit/creating_face-based_ar_experiences

некоторое время назад. Я попытался, и это вызывает проблемы во время выполнения.

Я использую iPhone XR, проект успешно строится и работает нормально. Но по крайней мере один процесс должен выполняться в главном потоке, но я не могу понять, какая это часть: /

Сообщение об ошибке выглядит как

2019-04-26 20:17:40.360763+0200 ARKitFaceExample[16979:3438178] [DYMTLInitPlatform] platform initialization successful
2019-04-26 20:17:40.551196+0200 ARKitFaceExample[16979:3438133] Metal GPU Frame Capture Enabled
2019-04-26 20:17:40.551498+0200 ARKitFaceExample[16979:3438133] Metal API Validation Enabled
2019-04-26 20:17:40.710761+0200 ARKitFaceExample[16979:3438133] [MC] System group container for systemgroup.com.apple.configurationprofiles path is /private/var/containers/Shared/SystemGroup/systemgroup.com.apple.configurationprofiles
2019-04-26 20:17:40.711381+0200 ARKitFaceExample[16979:3438133] [MC] Reading from public effective user settings.
=================================================================
Main Thread Checker: UI API called on a background thread: -[UIApplication applicationState]
PID: 16979, TID: 3438188, Thread name: com.apple.CoreMotion.MotionThread, Queue name: com.apple.root.default-qos.overcommit, QoS: 0
Backtrace:
4   libobjc.A.dylib                     0x000000021789f6f4 <redacted> + 56
5   CoreMotion                          0x000000021dfe9638 CoreMotion + 292408
6   CoreMotion                          0x000000021dfe9b68 CoreMotion + 293736
7   CoreMotion                          0x000000021dfe9a78 CoreMotion + 293496
8   CoreMotion                          0x000000021e0178a8 CoreMotion + 481448
9   CoreMotion                          0x000000021e0178ec CoreMotion + 481516
10  CoreFoundation                      0x000000021862b78c <redacted> + 28
11  CoreFoundation                      0x000000021862b074 <redacted> + 276
12  CoreFoundation                      0x0000000218626368 <redacted> + 2276
13  CoreFoundation                      0x0000000218625764 CFRunLoopRunSpecific + 452
14  CoreFoundation                      0x0000000218626498 CFRunLoopRun + 84
15  CoreMotion                          0x000000021e017280 CoreMotion + 479872
16  libsystem_pthread.dylib             0x00000002182a5920 <redacted> + 132
17  libsystem_pthread.dylib             0x00000002182a587c _pthread_start + 48
18  libsystem_pthread.dylib             0x00000002182addcc thread_start + 4
2019-04-26 20:17:40.745827+0200 ARKitFaceExample[16979:3438188] [reports] Main Thread Checker: UI API called on a background thread: -[UIApplication applicationState]
PID: 16979, TID: 3438188, Thread name: com.apple.CoreMotion.MotionThread, Queue name: com.apple.root.default-qos.overcommit, QoS: 0
Backtrace:
4   libobjc.A.dylib                     0x000000021789f6f4 <redacted> + 56
5   CoreMotion                          0x000000021dfe9638 CoreMotion + 292408
6   CoreMotion                          0x000000021dfe9b68 CoreMotion + 293736
7   CoreMotion                          0x000000021dfe9a78 CoreMotion + 293496
8   CoreMotion                          0x000000021e0178a8 CoreMotion + 481448
9   CoreMotion                          0x000000021e0178ec CoreMotion + 481516
10  CoreFoundation                      0x000000021862b78c <redacted> + 28
11  CoreFoundation                      0x000000021862b074 <redacted> + 276
12  CoreFoundation                      0x0000000218626368 <redacted> + 2276
13  CoreFoundation                      0x0000000218625764 CFRunLoopRunSpecific + 452
14  CoreFoundation                      0x0000000218626498 CFRunLoopRun + 84
15  CoreMotion                          0x000000021e017280 CoreMotion + 479872
16  libsystem_pthread.dylib             0x00000002182a5920 <redacted> + 132
17  libsystem_pthread.dylib             0x00000002182a587c _pthread_start + 48
18  libsystem_pthread.dylib             0x00000002182addcc thread_start + 4
2019-04-26 20:17:52.404466+0200 ARKitFaceExample[16979:3438187] [SceneKit] Error: Scene <SCNScene: 0x283b7a260> is modified within a rendering callback of another scene (<SCNScene: 0x283b68000>). This is not allowed and may lead to crash

со следующим сообщением на время выполнения :

Я надеюсь, что кто-то может мне помочь: /

Runtime message

1 Ответ

1 голос
/ 27 апреля 2019

В файле ViewController.swift , внутри расширения View Controller и метода rendering(), добавьте метод DispatchQueue.main.async.

DispatchQueue управляет выполнением работыПредметы.Каждый рабочий элемент, отправленный в очередь, обрабатывается в пуле потоков, управляемых системой.

extension ViewController: ARSCNViewDelegate {

    func renderer(_ renderer: SCNSceneRenderer, didAdd node: SCNNode, for anchor: ARAnchor) {

        DispatchQueue.main.async {

            guard let faceAnchor = anchor as? ARFaceAnchor else { return }
            self.currentFaceAnchor = faceAnchor

            if node.childNodes.isEmpty, let contentNode = self.selectedContentController.renderer(renderer, nodeFor: faceAnchor) {
                node.addChildNode(contentNode)
            }
        }
    }
}

Кроме того, преобразуйте Swift 4.2 вашего проекта в код Swift 5.0 и используйте цель iOS 12.2.

И, возможно, этот блок кода может быть более полезным, чем предыдущий:

extension ViewController: ARSCNViewDelegate {

    func renderer(_ renderer: SCNSceneRenderer, didAdd node: SCNNode, for anchor: ARAnchor) {

        DispatchQueue.global().async {

            guard let faceAnchor = anchor as? ARFaceAnchor else { return }
            self.currentFaceAnchor = faceAnchor

            DispatchQueue.main.async {

                if node.childNodes.isEmpty, let contentNode = self.selectedContentController.renderer(renderer, nodeFor: faceAnchor) {
                    node.addChildNode(contentNode)
                }
            }
        }
    }
}

Вот сообщения моей области отладки:

enter image description here

...