ARKit Image Recognition with a button

Hello,


I am working on an app that uses ARKit image recognition very similar to this sample:


https://developer.apple.com/documentation/arkit/recognizing_images_in_an_ar_experience


In my app, the ARViewController is being presented modally. I’m adding a button to the planeNode when an image is recognized. After adding the button, an SCNSnapshotWindow is added on top of the normal window. After dismissing the ARViewController modal, the SCNSnapshotWindow still exists and it’s blocking touches in my UI. After dismissal, the window isn't listed in UIApplication.shared.windows. I can only see the window if I use the Reveal App. The code is below. It’s mostly coming from the Apple sample code. Is there a way to make sure that this window gets removed when the view controller is dismissed?


func renderer(_ renderer: SCNSceneRenderer, didAdd node: SCNNode, for anchor: ARAnchor) {
        guard let imageAnchor = anchor as? ARImageAnchor else { return }
        let referenceImage = imageAnchor.referenceImage
        updateQueue.async {
       
            let plane = SCNPlane(width: referenceImage.physicalSize.width,
                                 height: referenceImage.physicalSize.height)
            let planeNode = SCNNode(geometry: plane)
            planeNode.opacity = 0.25
           
            let material = SCNMaterial()
           
            DispatchQueue.main.async {

                let button = UIButton(frame: CGRect(x: 0, y: 0, width: 100, height: 100))
                button.setImage(UIImage(named: “buttonImage”), for: .normal)
                button.addTarget(self, action: #selector(self.buttonPressed), for: .touchUpInside)
                material.diffuse.contents = button
            }
           
            planeNode.geometry?.firstMaterial = material

            planeNode.eulerAngles.x = -.pi / 2
            planeNode.runAction(self.imageHighlightAction)

            node.addChildNode(planeNode)
       }
}