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?
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)
...
}
}
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With