SceneKit presentScene (_withTransition: incomingPointOfView completeHandler) with SCNScene crash loading

I try to move from one scene to another, but when I call presentScene, it crashes! Scenes are not stored in the class or are not mentioned, they are loaded directly into the call presentScene.

Screenshot of an error in Xcode: crash screencap

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

MKSceneis just a subclass SCNScenebecause I would like to know when a scene starts to be sure it is.

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

then later I call

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 link to the scene in my class, then it works - but that's not what I want. I just want to go to another scene and leave the current scene behind the de-emitted one.

? , ...

+1
2

SceneKit. : "presentScene" .

+3

. MKScene . .

https://bugreport.apple.com rdar://24012973, , .

ViewController.swift. SCNScene ( 25/29) " " ( 24/28) .

        nextScene = SCNScene(named:"art.scnassets/scene2.scn")!

,

        nextScene = scene2!

.

//  ViewController.swift
import Cocoa
import SceneKit
import SpriteKit

class ViewController: NSViewController {

@IBOutlet weak var sceneView: SCNView!
private var sceneToggler:Bool = false
private var scene1: SCNScene? = SCNScene(named:"art.scnassets/scene1.scn")
private var scene2: SCNScene? = SCNScene(named:"art.scnassets/scene2.scn")

private func nextSceneToLoad() -> SCNScene {
    let nextScene: SCNScene

    if (sceneToggler) {
        //nextScene = SCNScene(named:"art.scnassets/scene1.scn")!
        nextScene = scene1!
        print ("scene1")
    }
    else {
        nextScene = SCNScene(named:"art.scnassets/scene2.scn")!
        //nextScene = scene2!
        print ("scene2")
    }
    print (nextScene)
    sceneToggler = !sceneToggler
    return nextScene
}

override func mouseUp(theEvent: NSEvent) {

    let skTransition:SKTransition = SKTransition.fadeWithDuration(5.0)
    skTransition.pausesIncomingScene = false
    skTransition.pausesOutgoingScene = false
    sceneView.presentScene(nextSceneToLoad(),
        withTransition:skTransition,
        incomingPointOfView:nil, completionHandler:nil)


    super.mouseUp(theEvent)
}
}
+2

Source: https://habr.com/ru/post/1626604/


All Articles