错误 "Thread 1: EXC_BAD_INSTRUCTION (code = EXC_1386_INVOP, subcode = 0x0)" 使用 Swift SpriteKit

Error "Thread 1: EXC_BAD_INSTRUCTION (code = EXC_1386_INVOP, subcode = 0x0)" Using Swift SpriteKit

我正在尝试 运行 GameViewController 中的 GameScene 函数,但收到上述错误。这是代码的基础知识:

在 GameScene 中调用:

func resetPosition(){
     someNode!.position = otherPosition! //this is the line with the error - otherPosition IS called previously as a CGPoint
}

在 GameViewController 中:

let gameScene = GameScene.self()

func reset(){ // reset is called by a UIButton
     gameScene.resetPosition()
}

模拟器打开并且 运行 正常,但是一旦按下链接到 reset 的按钮,应用程序就会崩溃。如果您需要更多代码,我很乐意提供。

听起来好像 someNodeotherPosition 都为零。你说前面调用了otherPosition,那肯定是someNode

如果在更新它的位置之前尝试展开 someNode 会发生什么情况?

if let someNode = someNode {
   someNode.position = otherPosition
} else {
    print("someNode was nil")
}