【发布时间】:2015-11-24 07:13:56
【问题描述】:
我正在使用一个共享项目,并且花了很多时间将其更新到 Swift 2,所以我想让它工作,但不幸的是我有一个运行时错误需要解决。故事板上什么都没有,所以一切都是以编程方式完成的。看到它是以编程方式完成的,我不确定为什么会出现这个运行时错误。
请告诉我这段代码中的“glasses1.dae”和“glasses2”是什么。这些是什么标识符?
Swift 的函数签名特化。(_fatalErrorMessage (Swift.StaticString, Swift.StaticString, Swift.StaticString, Swift.UInt) -> ()).(closure #2)
致命错误:在展开可选值时意外发现 nil (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()
}
【问题讨论】: