首页 > 解决方案 > ios 11.4 上的 SceneView hittest 崩溃,在 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 !
      // ...
      // ...
    }
  })
}

我在 hittest 行上收到“EXC_BAD_ACCESS (code=1, address=0x0)”崩溃。

任何想法如何解决这个问题?

标签: iosscenekitarkithittest

解决方案


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

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

推荐阅读