0

My app works perfect on iPhone6 but when I tested it on iPhone7 it crashes when I try to adjust points to an image.

Fatal Exception: CALayerInvalidGeometry CALayer position contains 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 says

Last Exception Backtrace (0)

at

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

Spent weeks on this. Any help is welcome!

ananai
  • 9
  • 1
  • 7
  • 1
    This thread may be helpful : https://stackoverflow.com/questions/4867968/calayerinvalidgeometry-reason-calayer-bounds-contains-nan-0-0-nan-nan-cr?rq=1 – technerd Mar 07 '18 at 07:17

1 Answers1

0

I would suggest that you add a check to make sure that the featurePointsBox rect doesn't contain any NaN values.

See the following thread: how to check for NaN value in Objective-C (iphone sdk)

Arik Segal
  • 2,963
  • 2
  • 17
  • 29