SWIFT: What does the Error “Thread 1:EXC_BAD_INSTRUCTION (code=EXC_I386_INVOP, subcode=0x0)” mean?

ぐ巨炮叔叔 提交于 2020-01-03 06:03:07

问题


I got this error, and how can I solve this error? When I run the app it crashes. It gives that error, Can anyone help? Thanks in advance.

The error is at the line: let initialAttitude = manager.deviceMotion!.attitude

// get magnitude of vector via Pythagorean theorem
        func magnitudeFromAttitude(attitude: CMAttitude) -> Double {
            return sqrt(pow(attitude.roll, 2) + pow(attitude.yaw, 2) + pow(attitude.pitch, 2))
        }

        // initial configuration
        let initialAttitude = manager.deviceMotion!.attitude //THIS IS THE LINE OF CODE WITH THE ERROR
        var showingPrompt = false

        // trigger values - a gap so there isn't a flicker zone
        let showPromptTrigger = 1.0
        let showAnswerTrigger = 0.8

        if manager.deviceMotionAvailable {
            manager.startDeviceMotionUpdatesToQueue(NSOperationQueue.mainQueue()) {
                [weak self] (data: CMDeviceMotion?, error: NSError?) in

                guard let data = data else { return }

来源:https://stackoverflow.com/questions/38603538/swift-what-does-the-error-thread-1exc-bad-instruction-code-exc-i386-invop-s

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!