SceneView hittest 在 ios 11.4 上崩溃,在 iOS 12+ 上运行

SceneView hittest crash on ios 11.4, runs on iOS 12+

我在 iOS 11.4 上遇到 m_sceneView.hittest(...) 函数崩溃。相同的代码在 iOS 12+ 上运行!

代码如下所示:

func renderer(_ renderer: SCNSceneRenderer, updateAtTime time: TimeInterval) {
  guard m_sceneView.session.currentFrame != nil else {return}

  DispatchQueue.main.async(execute: {
    if let camera = self.m_sceneView.session.currentFrame?.camera, 
                    case .normal = camera.trackingState {
      let results = self.m_sceneView.hitTest(self.m_sceneView.center, 
                    options: [SCNHitTestOption.searchMode: 2])
      guard let result = results.first else {
        print("No Hittest results received")
        return
      }

      // do something with the hittest result !
      // ...
      // ...
    }
  })
}

我在最命中行上遇到了 "EXC_BAD_ACCESS (code=1, address=0x0)" 崩溃。

有解决此问题的想法吗?

我从苹果公司那里得到了一个解决方案。它实际上是 SceneKit API 中的一个错误,已在 IOS 12 中解决,但是对于 12 之前的版本有一个解决方法:

let options: [SCNHitTestOption: Any] = [SCNHitTestOption.boundingBoxOnly: true]
let hitResults = scnView.hitTest(p, options: options)