TERMINATION堆栈在销毁时不为空。错误Swift

时间:2018-03-24 14:05:05

标签: swift runtime-error swift4 xcode9 google-vision

我正在使用Google Mobile Vision来检测面部地标以及它们之间的距离。这个错误的奇怪之处在于它不一致,并且不会一直显示我运行相同的函数。

以下是错误消息......

TERMINATION
ert_Error ebs_ObjectStack::~ebs_ObjectStack():
Stack is not empty at destruction.
This can be an indiaction for a stack leak.
Please check the code where this instance was used.

libc++abi.dylib: terminating with uncaught exception of type ert_Error
(lldb) 

通常我第一次在24小时内运行应用程序,一切顺利,偶尔也会发生。尽管它出现了大部分。正如我之前所说,我使用Google Mobile Vision来检测和存储某些值。

这是导致错误的函数......

func train2(image2: UIImage) {
    print("TRAIN2 has been called")
//  let options1 = [GMVDetectorFaceLandmarkType: GMVDetectorFaceLandmark.all.rawValue, GMVDetectorFaceClassificationType: GMVDetectorFaceClassification.all.rawValue, GMVDetectorFaceTrackingEnabled: true, GMVDetectorFaceMinSize: 0.09] as [String : Any]
    var deviceOrientation = UIDevice.current.orientation
    var devicePostion = AVCaptureDevice.Position.back   //.Position(rawValue: (currentCameraPosition?.hashValue)!)
    if CameraController().currentCameraPosition == .rear {
        devicePostion = AVCaptureDevice.Position.back
    }else if CameraController().currentCameraPosition == .front {
        devicePostion = AVCaptureDevice.Position.front
    }

    var lastKnownDeviceOrientation = UIDeviceOrientation(rawValue: 0)

    var orientation = GMVUtility.imageOrientation(from: deviceOrientation, with: devicePostion, defaultDeviceOrientation: lastKnownDeviceOrientation!)
    var options3 = [GMVDetectorImageOrientation:orientation.rawValue]

  //  var sampbuff = cvPixelBufferRef(from: image2)
  //  var AImage = GMVUtility.sampleBufferTo32RGBA(sampbuff as! CMSampleBuffer)

   var happyFaces = GfaceDetector.features(in: image2, options: options3) as! [GMVFaceFeature] // THE ERROR SEEMS TO ORIGINATE FROM THIS LINE

    print("The Amount Of Happy Faces is: \(happyFaces.count)")

    for face:GMVFaceFeature in happyFaces {
       print(face.smilingProbability)
        print("Go Google")
        var YAngle = Float(face.headEulerAngleY)
        var ZAngle = Float(face.headEulerAngleZ)
        print("Y Angle \(YAngle), Z Angle \(ZAngle)")
        if YAngle > -2.0 && YAngle < 4.0 && ZAngle > -2.0 && ZAngle < 2.0 {

            var proportion = ((face.bounds.width * face.bounds.width) + (face.bounds.height * face.bounds.height))
            var ratio = sqrtf(Float(proportion))


            DBetweenEyes = (Float(distanceBetween(face.leftEyePosition, face.rightEyePosition)) * 1000) / ratio
            DBetweenLEyeAndLEar = (Float(distanceBetween(face.leftEyePosition, face.leftEarPosition)) * 1000) / ratio
            DBetweenREyeAndREar = (Float(distanceBetween(face.rightEyePosition, face.rightEarPosition)) * 1000) / ratio
            DBetweenLEarAndREar = (Float(distanceBetween(face.leftEarPosition, face.rightEarPosition)) * 1000) / ratio

            DBetweenLEyeAndNose = (Float(distanceBetween(face.leftEyePosition, face.noseBasePosition)) * 1000) / ratio
            DBetweenREyeAndNose = (Float(distanceBetween(face.rightEyePosition, face.noseBasePosition)) * 1000) / ratio
            DBetweenLEyeAndMouth = (Float(distanceBetween(face.leftEyePosition, face.bottomMouthPosition)) * 1000) / ratio

            DBetweenREyeAndMouth = (Float(distanceBetween(face.rightEyePosition, face.bottomMouthPosition)) * 1000) / ratio
            DBetweenLEarAndMouth = (Float(distanceBetween(face.leftEarPosition, face.bottomMouthPosition)) * 1000) / ratio
            DBetweenREarAndMouth = (Float(distanceBetween(face.rightEarPosition, face.bottomMouthPosition)) * 1000) / ratio


            print("Distances Established")
        }
    }



}

我刚刚发现在视图加载后按下按钮时调用该错误非常罕见。在viewDidLoad方法中调用时,错误发生得更频繁。这可能表明某种模式吗?我该如何解决这个错误?

任何帮助或建议都有帮助。 提前谢谢!

0 个答案:

没有答案