2012-07-18 11 views
12

Tengo un error donde bloquea la aplicación cuando se está iniciando. Este es el error que me dieron:Cómo resolver CALayerInvalidGeometry ', razón:' La posición de CALayer contiene 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 

He intentado utilizar punto de interrupción de excepción y que no muestra qué parte del código ha ido wrong.It sólo se detienen en este punto -0xbc74e: MOVL $ 0,% eax -

¿Cómo puedo resolverlo? Por favor ayuda.

* Editar

He encontrado la parte que produce la excepción, pero no puedo ver lo que está mal

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

} 

Esta línea está causando el error self.mapView.layerDelegate = self; que por defecto llamar al método mapViewDidLoad

+1

Alguien sabe cómo resolver? – sihao

Respuesta

4

Creo que este error se produce porque la capa que se ejecuta tiene el marco en esta forma:

Capa frame == {{inf, inf}, {0, 0}}

Aquí inf es infimum. Su conjunto de números.

Así que la solución para evitar este tipo de problema simplemente crea una condición antes de que regrese la capa. como como:

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

Dónde capa simple es como como:

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

Esta condición resuelto mi problema. Intentalo.

+7

Gracias por responder. Pero no puedo encontrar la parte que recibió el error. ¿Dónde podría poner el código? ¿algún consejo? – sihao

-1

Sé que esta pregunta no es muy reciente, pero solo quiero dar una respuesta. De todos modos, supongo que su mapView es de AGSMapView y se ha inicializado esta manera:

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

Ahora, creo que el mejor, si no la única forma correcta, para inicializar está utilizando initWithFrame. Aunque no estoy seguro de por qué, mapView está roto si usa init para la inicialización.

Espero que esto ayude.

1

Para mí fue causado por la toView en este código es nula:

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