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

查看:183
本文介绍了添加具有强引用的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:)被调用,并且场景视图冻结后,日志中几乎没有[Technique] World tracking performance is being affected by resource constraints [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:

根据锚的 identifier 属性将其视为相等.

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.

您可以按照以下方式使用某些东西:

You could use something along the lines of:

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

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

}

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

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