Export ARSCNFaceGeometry wrapped in MDLAsset fail on iOS 14 with EXC_BAD_ACCESS

Viewed 334

I have an application that exploits ARKit's face tracking feature to build .obj face model files. It generally follows practices in Tracking and visualizing faces. The app gets the anchor in func renderer(_ renderer: SCNSceneRenderer, didAdd node: SCNNode, for anchor: ARAnchor), and update the geometry in func renderer(_ renderer: SCNSceneRenderer, didUpdate node: SCNNode, for anchor: ARAnchor).

For the face model export, the following function is used, which wraps the ARSCNFaceGeometry in a MDLAsset and export the asset. The code is as follows.

func exportMesh(_ geometry: SCNGeometry, to url: URL, completion: (() -> ())?) {
    DispatchQueue.global().async {
        let mesh = MDLMesh(scnGeometry: geometry)
        let asset = MDLAsset()
        asset.add(mesh)
        do {
            try asset.export(to: url)
        } catch {
            print("Can't write mesh to url")
        }
        DispatchQueue.main.async {
            completion?()
        }
    }
}

The application works fine before on iOS 13. However, when I installed it on iOS 14, the app crashes on the line try asset.export. The do-catch syntax did not catch the error, it directly crashes with EXC_BAD_ACCESS. I tried to export only a SCNBox in this step and it worked fine, seems it has something to do with the ARSCNFaceGeometry.

My Mac and the test device are all updated to the newest system, the test device is an iPhone X.

A screen shot may be helpful.

screenshot

I would be so appreciate if you could provide some hint.

1 Answers

Maybe I'm a bit late but I ran into a similar crash when exporting SCNGeometry. The last callstack frame '_platform_strlen' led me to something string-related. So in my case I just assigned a name to each material referenced by the SCNGeometry instance.

Related