12

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?

1
  • Hi, do you found how to solve the issue? May 8, 2019 at 14:11

3 Answers 3

11

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)

            ...
        }
    }
1
  • Well if you are dealing with one node creation without logic in it looks easy.
    – Hope
    Jun 9, 2020 at 13:26
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.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.