【问题标题】:Memory issue when loading usdz files加载 usdz 文件时的内存问题
【发布时间】:2019-11-02 03:29:39
【问题描述】:

我正在将一个 .usdz 文件加载到我的 ARSCNView 中,到目前为止它工作正常,除了当我将多个对象加载到我的场景中时应用程序崩溃并显示消息:由于内存问题而终止。

我使用的是 Apple 的默认 .usdz 示例 (https://developer.apple.com/augmented-reality/quick-look/),机器人文件大约 13.5MB 大。

它最多可用于 4-5 个实例,然后崩溃。

ARKit 应用的限制这么小,还是我做错了什么?

这是我的代码:

// 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)
}

【问题讨论】:

    标签: ios swift memory-management arkit usdz


    【解决方案1】:

    应用程序可以分配一定数量的内存,如果超过,它会被操作系统自动终止。 我在 iPhone 6S 上测试了一个简单的ARKit 应用程序,添加一个大小约为 13.5MB 的单个 usdz 文件会增加应用程序的内存使用量约 280MB,应用程序的内存限制为 1.37GB,如 Xcode 的内存报告部分所示:

    您可以看到每次将相同的 usdz 文件再次添加到场景中时内存使用量如何增加。 因此,从技术上讲,您不能(也可能不应该)向您的应用同时添加多个 usdz 文件。

    【讨论】:

      猜你喜欢
      • 2016-01-17
      • 1970-01-01
      • 2012-03-14
      • 1970-01-01
      • 1970-01-01
      • 2010-11-24
      • 1970-01-01
      • 2011-06-26
      • 1970-01-01
      相关资源
      最近更新 更多