应用程序仅在iPhone7上崩溃:致命异常:CALayerInvalidGeometry CALayer位置包含NaN:[nan nan]

时间:2018-03-07 06:48:41

标签: ios objective-c xcode crash

我的应用程序在iPhone6上运行完美,但是当我在iPhone7上测试它时,当我尝试将点调整为图像时,它会崩溃。

  

致命异常:CALayerInvalidGeometry   CALayer位置包含NaN:[nan nan]

- (void)adjustPointsToFaceModel {

FaceFeatures *features = self.faceFeaturesModel.features;

CGRect featurePointsBox = [self.view featuresBoundingBox];

[self.view.featurePointsMapping enumerateKeysAndObjectsUsingBlock:^(NSNumber* key, FeaturePointView* view, BOOL *stop) {
    FaceFeaturePoint feature = key.unsignedIntegerValue;
    CGPoint pointCenter = [self.view convertPointFromImage:[features coordinatePointForFeature:feature]];

    if (pointCenter.x < CGRectGetMinX(featurePointsBox)) {
        pointCenter.x = CGRectGetMinX(featurePointsBox);
    }
    if (pointCenter.y < CGRectGetMinY(featurePointsBox)) {
        pointCenter.y = CGRectGetMinY(featurePointsBox);
    }
    if (pointCenter.x > CGRectGetMaxX(featurePointsBox)) {
        pointCenter.x = CGRectGetMaxX(featurePointsBox);
    }
    if (pointCenter.y > CGRectGetMaxY(featurePointsBox)) {
        pointCenter.y = CGRectGetMaxY(featurePointsBox);
    }
    view.center = pointCenter;
}];

[self.view layoutIfNeeded];
}

XCode说

  

Last Exception Backtrace(0)

at

[self.view.featurePointsMapping enumerateKeysAndObjectsUsingBlock:^(NSNumber* key, EMFeaturePointView* view, BOOL *stop) {

花了好几周时间。欢迎任何帮助!

1 个答案:

答案 0 :(得分:0)

我建议您添加一项检查以确保featurePointsBox rect不包含任何NaN值。

请参阅以下主题: how to check for NaN value in Objective-C (iphone sdk)