Search code examples
iosscenekitarkithittest

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


I am experiencing a crash of the m_sceneView.hittest(...) function on iOS 11.4. The same code runs on iOS 12+ !

Code looks like this:

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 !
      // ...
      // ...
    }
  })
}

I get a "EXC_BAD_ACCESS (code=1, address=0x0)" crash on the hittest line.

  • I have checked that the self.m_sceneView.center contains valid values
  • I am checking for the session state (as you see in the code)
  • The problem is reproducible.
  • The view I am operating on is an ARSCNView

Any ideas how to fix this issue ?


Solution

  • I got a Solution from Apple guys. It is actually a bug in the SceneKit API which was solved in IOS 12, but there is a workaround for versions earlier than 12:

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