17

I have an error where it crash the application when it is starting up. This is the error that i got:

*** Terminating app due to uncaught exception 'CALayerInvalidGeometry', reason: 'CALayer position contains NaN: [nan nan]'
*** First throw call stack:
(0x250b022 0x2709cd6 0x24b3a48 0x24b39b9 0x217ec0d 0x2174f55 0x158f3f7 0xbc74e 0xbe512 0xbfa26 0xbe4ad 0x224ffda 0x224f956 0x224e449 0x224ab9a 0x24df970 0x247f1c1 0x2442967 0x2441d84 0x2441c9b 0x2c0a7d8 0x2c0a88a 0x1559626 0x2aed 0x2a65)
terminate called throwing an exception

i tried using Exception breakpoint and it doesn't show which part of the code has gone wrong.It only stop at this point -0xbc74e: movl $0, %eax-

How can i solve it? Please help.

*edit

I found the part which throws the exception but i can't see what is wrong

- (void)viewDidLoad {
[super viewDidLoad];
[self.activityView startAnimating];
self.mapView.layerDelegate = self;
self.mapView.touchDelegate = self;
self.mapView.calloutDelegate = self;

NSURL *mapUrl = [NSURL URLWithString:kTiledMapServiceURL];
AGSTiledMapServiceLayer *tiledLyr = [AGSTiledMapServiceLayer tiledMapServiceLayerWithURL:mapUrl];
[self.mapView addMapLayer:tiledLyr withName:@"Tiled Layer"];
        .
        .
        .
}
- (void)mapViewDidLoad:(AGSMapView *)mapView {

AGSEnvelope *envelope = [[AGSEnvelope alloc]initWithXmin:29757.610204117 ymin:40055.0379682464 xmax:29884.6992302249 ymax:40236.6028660071 spatialReference:self.mapView.spatialReference];

//call method to set extent, pass in envelope
[self.mapView zoomToEnvelope:envelope animated:YES];

self.mapView.callout.width = 195.0f;
self.mapView.callout.accessoryButtonHidden = YES;

[self.mapView.gps start];
[self.mapView centerAtPoint:self.mapView.gps.currentPoint animated:YES];  

[self.activityView stopAnimating];
self.activityView.hidden = YES;

}

This line is causing the error self.mapView.layerDelegate = self; which by default call the method mapViewDidLoad

sihao
  • 273
  • 2
  • 5
  • 19

3 Answers3

5

I think this error occurs because the layer which is executed has frame in this form:

Layer frame == {{inf, inf}, {0, 0}}

Here inf is infimum. Its set of numbers.

So the solution to avoid this kind of issue just create condition before return of layer. Like as:

if (layer.frame.size.width ==0 || layer.frame.size.height ==0 ) {
    return [self simpleLayer];
}else{
    return layer;        
} 

Where simple layer is like as :

-(CALayer *)simpleLayer{
    CALayer *layer = [[CALayer alloc] init];
    [layer setFrame:CGRectMake(0, 0, 10, 10)];
    [layer setHidden:TRUE];
    return layer;
}

This condition solved my issue. Try it.

Nilesh Tripathi
  • 100
  • 1
  • 11
  • 8
    Thanks for answering. But i can't find which part got the error. where could i possibly put the code at? any advice? – sihao Jul 25 '12 at 01:17
1

For me it was caused by the toView in this code being nil:

    [UIView transitionFromView:self.fromView
                        toView:self.toView
                      duration:0.6
                       options:(currentPage > toPage ? UIViewAnimationOptionTransitionCurlDown : UIViewAnimationOptionTransitionCurlUp)
                    completion:^(BOOL finished) {
                        if (finished) {
                        }
                    }
Andrew Bennett
  • 910
  • 11
  • 11
-1

I know this question is not very recent but I just want to give an answer. Anyway, I'm guessing your mapView is of AGSMapView and you have initialized it this way:

self.mapView = [[[AGSMapView alloc] init] autorelease];

Now, I think the better, if not the only correct way, to initialize it is using initWithFrame. Though I'm not sure why, mapView is broken if you use init for the initialization.

Hope this helps.

yoninja
  • 1,952
  • 2
  • 31
  • 39