添加 14 个具有强引用的 ARAnchor 子类对象时 ARSCNView 冻结 [英] ARSCNView freezes when adding 14 ARAnchor subclass objects with strong reference

查看:40
本文介绍了添加 14 个具有强引用的 ARAnchor 子类对象时 ARSCNView 冻结的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有下一个代码:

    guard let feauturePoint = frame.hitTest(normalizedPoint, types: .featurePoint).first?.worldTransform else {
        return
    }
    let anchor = MyAnchorSubclass(transform: feauturePoint, plus: someAdditionalInfo)
    arSession.add(anchor: anchor)

此函数创建并添加我的 ARAnchor 子类的对象.然后……

This function creates and adds object of my subclass of ARAnchor. Then...

    func renderer(_ renderer: SCNSceneRenderer, didAdd node: SCNNode, for anchor: ARAnchor) {
        guard let anchor = anchor as? MyAnchorSubclass else { return }
        anchors.append(anchor)
        /* then goes some my logic with adding SCNNode */
    }

... 渲染锚点后,我将在那里添加我的 SCNNode.但是,当我使用 anchors.append(anchor) 时,其中 anchors[MyAnchorSubclass],场景在添加 14 个锚点后立即冻结.如果我不将锚点保存在数组中,则场景视图不会冻结.

... after anchor was rendered, I'm adding my SCNNode there. But, when I'm using anchors.append(anchor), where anchors is [MyAnchorSubclass], scene freezes right after 14 added anchors. If I'm not saving anchor in array, scene view does not freezes.

有人知道是什么吗?iOS 11 Beta 错误或某种限制?

Does anyone know what is it? iOS 11 Beta bug or some kind of limitations?

更新

最后,会发生什么 - renderer(_:didUpdate:for:) 被调用,在它之后场景视图冻结并且很少 [技术] 世界跟踪性能受到资源限制的影响[0] 消息出现在日志中.

Last, what happens - is renderer(_:didUpdate:for:) being called and after it scene view freezes and few [Technique] World tracking performance is being affected by resource constraints [0] messages appears in log.

更新 1

有趣的事实:在应用程序进入后台并返回后,sessionWasInterrupted(:)sessionInterruptionEnded(:) 被调用,即使场景视图之前被冻结.

Interesting fact: after app goes to the background and returns back, sessionWasInterrupted(:) and sessionInterruptionEnded(:) being called, even though scene view was freezed before.

推荐答案

好的,您的问题是,您不想维护自己的锚点数组.您希望维护每个锚点的 标识符 (UUID) 数组.在 Apple 文档中:

Ok, your issue is, you don’t want to be maintaining your own array of the anchors. You want to be maintaining an array of the identifiers (UUID) of each anchor. In Apple docs:

根据锚点的标识符属性,它们被认为是相等的.

Anchors are considered equal based on their identifier property.

原因是,ARKit 在后台线程上调用 init(anchor:) 以将锚类的实例从 每个 ARFrame 复制到下一个.在存储每个 ARAnchor 的数组时,您只能及时保留这些锚点的一组实例,否则 ARKit 会丢弃这些实例.

Reason being, ARKit calls init(anchor:) on a background thread to copy instances of your anchor class from each ARFrame to the next. In storing an array of each ARAnchor you are only holding-on to one set of instances of those anchors in time, that would otherwise have been discarded by ARKit.

使用你的UUID锚点数组,如果你需要引用一个,遍历当前ARFrame会话中的锚点,搜索UUID一个你需要做的事情.

With your array of UUIDs of the anchors, if you need to reference one, iterate through the anchors in the session for the current ARFrame, searching for the UUID of the one you need to do something with.

您可以使用以下内容:

func anchorForID(_ anchorID: UUID) -> ARAnchor? {

    return session?.currentFrame?.anchors.first(where: { $0.identifier == anchorID })

}

这篇关于添加 14 个具有强引用的 ARAnchor 子类对象时 ARSCNView 冻结的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆