本文介绍了动态加载的SCNScene导致SceneKit presentScene(_withTransition:incomingPointOfView completeHandler)崩溃的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正试图从一个场景过渡到另一个场景,但是当我调用 presentScene 时,会发生崩溃!
场景未存储在类中或未引用,它们被直接加载到 presentScene 调用中。

I'm trying to transition from one scene to another, but when I call presentScene there is a crash!The scenes are not stored in a class or referenced, they are loaded directly into the presentScene call.

Xcode中的崩溃屏幕截图:

Screenshot of crash in Xcode:

我简单的最小项目在这里:

My simple minimal project is here: https://dl.dropboxusercontent.com/u/6979623/SceneKitTransitionTest.zip

MKScene 只是<$ c的子类$ c> SCNScene ,因为我想知道何时初始化场景以确保是这样。

MKScene is just a subclass of SCNScene, because I would like to know when a scene is deinited to be sure that is it.

self.gameView!.scene = MKScene(named:"art.scnassets/scene1.scn")

然后我打电话

let scnView:SCNView = self.gameView! as SCNView
let skTransition:SKTransition = SKTransition.crossFadeWithDuration(1.0)
skTransition.pausesIncomingScene = false
skTransition.pausesOutgoingScene = false
self.sceneToggler = !self.sceneToggler
// transition
scnView.presentScene((self.sceneToggler ? MKScene(named:"art.scnassets/scene1.scn")! : MKScene(named:"art.scnassets/scene2.scn")!), withTransition:skTransition, incomingPointOfView:nil, completionHandler:nil)

如果我继续引用场景然后我的课就可以了-但这不是我想要的。我只想过渡到其他场景,而将当前场景保留为未初始化状态。

If I keep a reference to the scene in my class then it works – but that's not what I want. I just want to transition to a different scene and leave the current scene behind deinited.

为什么会崩溃?
似乎只是一个简单的任务……

Why is this crashing?It seems like a simply task…

推荐答案

这是SceneKit中的错误。解决方法:在调用 presentScene之前保留对传出场景的引用,并在该调用之后释放它。

That's a bug in SceneKit. Workaround: keep a reference to the outgoing scene before calling "presentScene" and release it after that call.

这篇关于动态加载的SCNScene导致SceneKit presentScene(_withTransition:incomingPointOfView completeHandler)崩溃的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

11-02 10:21