2

I'm loading a .usdz file into my ARSCNView and so far it works fine, except from the fact that when I load multiple objects into my scene the app crashes with message: Terminated due to memory issue.

I'm using Apple's default .usdz samples (https://developer.apple.com/augmented-reality/quick-look/) and the robot file is around 13.5MB big.

It works with up to 4-5 instances and then crashes.

Is the limit for ARKit application so small, or am I doing something wrong?

Here's my code:

// My touch point on the screen
let touchLocation = sender.location(in: sceneView)    

// We have a touch point on an ARPlane
if let result = self.sceneView.hitTest(touchLocation, types: ARHitTestResult.ResultType.existingPlaneUsingExtent).last {

    let position = SCNVector3Make(result.worldTransform.columns.3.x, result.worldTransform.columns.3.y, result.worldTransform.columns.3.z)

    // Load the .usdz model        
    guard let usdzURL = Bundle.main.url(forResource: "toy_robot_vintage", withExtension: "usdz") else {
        return
    }

    // Create a node, set position and scale
    let referenceNode = SCNReferenceNode(url: usdzURL)!
    referenceNode.load()
    referenceNode.position = position
    referenceNode.scale = SCNVector3Make(0.01, 0.01, 0.01)

    // Add node to scene
    sceneView.scene.rootNode.addChildNode(referenceNode)
}
M Reza
  • 18,350
  • 14
  • 66
  • 71
Pikebu
  • 101
  • 2
  • 6

1 Answers1

0

There's a certain amount of memory an app can allocate and if it exceeds, it's automatically killed by the OS. I tested a simple ARKit app on an iPhone 6S, adding a single usdz file with around 13.5MB of size adds around 280MB to the app's memory usage and the memory limit for the app is 1.37GB as shown in Xcode's Memory Report section:

enter image description here

You can see how memory usage increases each time the same usdz file is added to the scene again. So technically you cannot (and probably shouldn't) add more than a couple of usdz files at the same time to your app.

M Reza
  • 18,350
  • 14
  • 66
  • 71