2012-07-18 80 views
12

我有一個錯誤,它在應用程序啓動時崩潰。 這是我得到的錯誤:如何解決CALayerInvalidGeometry',原因:'CALayer的位置包含NaN:[nan nan]?

*** 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 

我使用異常斷點嘗試,它並不顯示哪些部分的代碼已經只有wrong.It在此時停止-0xbc74e:MOVL $ 0,%EAX -

我該如何解決它?請幫忙。

*編輯

我發現它拋出異常的一部分,但我看不出有什麼不對

- (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; 

} 

此行是導致錯誤self.mapView.layerDelegate = self;它默認調用方法mapViewDidLoad

+1

人知道如何解決? – sihao 2012-07-24 07:14:38

回答

4

我覺得這個錯誤發生是因爲被執行的圖層有這樣的格式:

Layer幀== {{INF,INF},{0,0}}

這裏INF是下确界。它的數字集。

因此,避免這種問題的解決方案只是在返回圖層之前創建條件。 像爲:

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

如果簡單的一層是像爲:

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

這種情況解決了我的問題。嘗試一下。

+7

感謝您的回答。但是我找不到哪個部分出錯。我可以在哪裏放置代碼?有什麼建議? – sihao 2012-07-25 01:17:18

-1

我知道這個問題不是很近,但我只想給出答案。無論如何,我猜你的mapViewAGSMapView和你這樣初始化它:

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

現在,我想好了,如果不是唯一正確的道路,它是用initWithFrame初始化。雖然我不確定爲什麼,如果您使用init進行初始化,mapView會中斷。

希望這會有所幫助。

1

對我來說,它是由在這個代碼是零的toView造成的:

[UIView transitionFromView:self.fromView 
         toView:self.toView 
         duration:0.6 
         options:(currentPage > toPage ? UIViewAnimationOptionTransitionCurlDown : UIViewAnimationOptionTransitionCurlUp) 
        completion:^(BOOL finished) { 
         if (finished) { 
         } 
        } 
相關問題