gpt4 book ai didi

ios - 加载 usdz 文件时出现内存问题

转载 作者:行者123 更新时间:2023-11-28 07:25:42 26 4
gpt4 key购买 nike

我正在将一个 .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)
}

最佳答案

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

enter image description here

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

关于ios - 加载 usdz 文件时出现内存问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/56666857/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com