masaldana2
masaldana2

Reputation: 654

ARMeshAnchor – SceneKit SCNView Renderer EXC_BAD_ACCESS

Im converting the ARMeshAnchor data to mesh using SCNGeometrySource which it works fine but sometimes 3/10 I will get a bad_access from SceneKit renderer.

[![enter image description here][1]][1]

Upvotes: 2

Views: 485

Answers (1)

Andy Jazz
Andy Jazz

Reputation: 58553

It occurs because ARMeshAnchors constantly update their data as ARKit refines its understanding of the real world. All ARMeshAnchors are dynamic anchors. However their mesh's subsequent changes are not intended to reflect in real time.

If you want to duplicate your ARMeshAnchors collection use the following code:

var anchorsArray = [ARMeshAnchor]()
    
let frame = arView.session.currentFrame
    
let meshAnchors = frame?.anchors.compactMap { $0 as? ARMeshAnchor }
    
anchorsArray += meshAnchors!

Every ARMeshAnchor is connected with primitive geometry data that's stored in MTLBuffer:

anchorsArray[0].geometry.faces.buffer
anchorsArray[0].geometry.vertices.buffer
anchorsArray[0].geometry.normals.buffer
anchorsArray[0].geometry.classification?.buffer

Upvotes: 2

Related Questions