我正在使用一个共享项目,并花费了大量时间将其更新为Swift 2,所以我想让它正常工作,但不幸的是,我有一个运行时错误需要处理。故事板上没有任何东西,所以一切都是通过编程完成的。看到它是通过编程完成的,我不知道为什么要得到这个运行时错误。
请告诉我这个代码中的"glasses1.dae“和"glasses2”是什么。这些是什么标识符?
Swift.(_fatalErrorMessage (Swift.StaticString,Swift.UInt) -> ())的函数签名专门化(闭包#2) 致命错误:在展开可选值(lldb)时意外找到零 线1: EXC_BAD_INSTRUCTION .
class ViewController: UIViewController {
private let notificationCenter : NSNotificationCenter = NSNotificationCenter.defaultCenter()
private let screenWidth : CGFloat = 320
private let scaleX : CGFloat = (320 / 750)
private let scaleY : CGFloat = (568 / 1334)
private let eyeRectL : UILabel = UILabel()
private let eyeRectR : UILabel = UILabel()
private var scnView : SCNView!
private var glasses : SCNNode!
override func viewDidLoad() {
super.viewDidLoad()
// Scene
let scene = SCNScene(named: "glasses1.dae")! // fatal error: unexpectedly found nil while unwrapping an Optional value
// Camera
let cameraNode = SCNNode()
cameraNode.camera = SCNCamera()
cameraNode.position = SCNVector3(x: 0, y: 0, z: 0)
scene.rootNode.addChildNode(cameraNode)
// Light
let lightNode = SCNNode()
lightNode.light = SCNLight()
lightNode.light!.type = SCNLightTypeOmni
lightNode.position = SCNVector3(x: 0, y: 10, z: 10)
scene.rootNode.addChildNode(lightNode)
// Ambient Light
let ambientLightNode = SCNNode()
ambientLightNode.light = SCNLight()
ambientLightNode.light!.type = SCNLightTypeAmbient
ambientLightNode.light!.color = UIColor.darkGrayColor()
scene.rootNode.addChildNode(ambientLightNode)
glasses = scene.rootNode.childNodeWithName("glasses2", recursively: true)! // what is "glasses2"?
scnView = SCNView()
scnView.scene = scene
scnView.backgroundColor = UIColor.clearColor()
scnView.frame = self.view.bounds
let moohaha = setupMoohaha()
let cameraView = visage.moohahaCameraView
self.view.addSubview(cameraView)
self.view.addSubview(scnView)
self.view.addSubview(eyeRectL)
self.view.addSubview(eyeRectR)
moohaha.beginFaceDetection()
}发布于 2015-11-23 05:23:58
.dae文件包含场景信息,用于加载外部创建的场景(不是在代码中)。这个"glasses1.dae“字符串是应该成为项目一部分的文件的名称。据推测,childWithNodeName(_:recursively:)方法调用用于查找名为"glasses2“的子节点,该子节点是作为用于创建场景的.dea文件中定义的场景的一部分创建的。
您所指示的两行末尾的!操作符用于强制展开一个可选值,如果该值包含nil,它将使程序崩溃。因此,我假设您的场景没有被创建,因为"glasses.dea“文件实际上不是您项目的一部分,而且SceneKit无法加载它并返回一个nil场景。
https://stackoverflow.com/questions/33864033
复制相似问题