13

I am using ARKit image tracking configuration, once an image is detected, a 3D scene would pop up on the image.

But when I set two different images to trigger two different scene file, one image always has two different scene files pop up at the same image. I am pretty sure the images are different, the names are different, the scene file are different, the contents of scene are different as well.

Once the image is detected, below error pops up in the console as well:

[SceneKit] Error: Scene <SCNScene: 0x284ebcfa0> is modified within a rendering callback of another scene (<SCNScene: 0x28099c820>). This is not allowed and may lead to crash

Any reason and solution for this error?

Matt Bierner
  • 58,117
  • 21
  • 175
  • 206
Tinloy
  • 191
  • 2
  • 7

3 Answers3

12

I had the same error with ARKit 2 in the image tracking. And after hours trying, I found the solution. Apparently you need to create your nodes in the background thread to be able to play with the scenes. This was my code:

DispatchQueue.main.async {
        if let imageAnchor = anchor as? ARImageAnchor {

            let plane = SCNPlane(width: imageAnchor.referenceImage.physicalSize.width, height: imageAnchor.referenceImage.physicalSize.height)
            plane.firstMaterial?.diffuse.contents = UIColor(white: 1.0, alpha: 0.5)

            let planeNode = SCNNode(geometry: plane)
            planeNode.eulerAngles.x = -.pi
            node.addChildNode(planeNode)

            ...
        }
    }
Diego Isco
  • 499
  • 3
  • 12
3

If you code like below, the error pops up.

func renderer(_ renderer: SCNSceneRenderer, nodeFor anchor: ARAnchor) -> SCNNode? {
    guard let imageAnchor = anchor as? ARImageAnchor else {
        return nil
    let buttonNode = SCNScene(named: "art.scnassets/social_buttons.scn")!.rootNode.childNode(withName: "card", recursively: false)
}

This is because you call new SCNScene (init new SCNScene) in renderer method.

Init SCNScene in viewDidLoad or other place. If so, the error might disappear.

0

I was getting this error because I was calling scene.isPaused = false, and removing that line got rid of the console error. Are you performing any modifications to your SCNScene? That would be a good place to start isolating the source of the error.

Andy Novak
  • 378
  • 5
  • 11