0

My app is a simple news app,It contains a sections button .When we click the button on leftside it will show up a popover with lots of items (like sports,politics,regional news,international news, games etc.) When i click these items it will will load the contents from xml and display to a webview.

But wen i tried to click some items like maximum 3 to 4 continueusly the app is crashing. app crashing only in ipad 1(iOS 5.1) and in ipad 3 its working fine (iOS6.1.3). I got the crash log when i run the app in simulator .

CRASH LOGS

*** Terminating app due to uncaught exception 'CALayerInvalidGeometry', reason: 'CALayer position contains NaN: [nan nan]' 
*** First throw call stack: 
(0x236e022 0x1802cd6 0x2316a48 0x23169b9 0x7c5c0d 0x7bbf55 0x1a227d3 0xb03fae 0xd0eff3 0xb0307e 0x236fdea 0x22d97f1 0x9be27d 0x9aa9ae 0x9bc86f 0x9ab70f 0x9abd07 0x10aa7 0x9f65c5 0x9f67fa 0x128b85d 0x2342936 0x23423d7 0x22a5790 0x22a4d84 0x22a4c9b 0x1dfb7d8 0x1dfb88a 0x965626 0x22cd 0x21f5) 
terminate called throwing an exception(lldb)

following drawing shows the simple drawing

enter image description here

the webview placed inside a scroll view

Please check the following codes

-(void)loadpages:(int)page{

    if((page>links.count-1)||(page<0))
        return;


        NSURLRequest *request=[NSURLRequest requestWithURL:[NSURL fileURLWithPath:HTMLPath]];

    if(([[[[[scrollView subviews] objectAtIndex:page] request] URL] absoluteString] ==nil)||(page==0)||(page==31))
    {

           [[[self.scrollView subviews] objectAtIndex:page] loadRequest:request];

    }else if([[[[[[scrollView subviews] objectAtIndex:page] request] URL] absoluteString] isEqualToString:@"about:blank"]){

           [[[self.scrollView subviews] objectAtIndex:page] loadRequest:request];

    }

}






- (void)scrollViewDidScroll:(UIScrollView *)sender {

    if (sender==scrollView) {
        // Update the page when more than 50% of the previous/next page is visible
        CGFloat pageWidth = scrollView.frame.size.width;
        int page = floor((self.scrollView.contentOffset.x - pageWidth / 2) / pageWidth) + 1;
        if(currentPage!= page){
            currentPage = page;
            // NSLog(@"currentpage:%d",currentPage);

            NSDictionary * news = (NSDictionary *)[links objectAtIndex:page];
            if (page==0) {
                Title_buttonItem.hidden=NO;
                [Title_lbl setText:nil];
                [Title_buttonItem setTitle:nil forState:UIControlStateNormal];
                [Title_buttonItem setImage:[UIImage imageNamed:@"Logo1.png"] forState:UIControlStateNormal];
            }else{

                [Title_lbl setText:[news objectForKey:@"title"]];
                Title_buttonItem.hidden=YES;
            }

            if (_lastContentOffset < (int)sender.contentOffset.x) {
                // moved right
                if (currentPage==31) {
                    TwoPage=currentPage;
                    allpage=0;
                    [self loadpages:currentPage];
                } else {
                    TwoPage=currentPage;
                    allpage=0;
                    [self loadpages:currentPage];
                    [self loadpages:currentPage+1];
                }

            }
            else {
                // moved left
                TwoPage=0;

                if (currentPage==0) {
                    allpage=currentPage;
                    [self loadpages:currentPage];
                }else{
                    allpage=currentPage;
                    [self loadpages:currentPage];
                    [self loadpages:currentPage-1];
                }

            }

            if ([Checking_DistrictPage isEqualToString:@"YES"]) {

                if (currentPage<([Title_Sections count]-[Title_Districts count])) {

                    frame.origin.x = (self.scrollView.frame.size.width) * MovePage;
                    self.scrollView.contentSize = CGSizeMake(self.scrollView.frame.size.width * [links count],self.scrollView.frame.size.height);
                    [scrollView scrollRectToVisible:CGRectMake(([Title_Sections count]-[Title_Districts count])*scrollView.frame.size.width, 0, scrollView.frame.size.width, scrollView.frame.size.height) animated:NO];
                    //[[[self.scrollView subviews] objectAtIndex:page] loadRequest:request];

                }else{
                    frame.origin.x = (self.scrollView.frame.size.width) * MovePage;
                    self.scrollView.contentSize = CGSizeMake(self.scrollView.frame.size.width * [links count],self.scrollView.frame.size.height);
//                    if (Check_district==YES) {
//                        splashImage =[[UIImageView alloc]initWithFrame:CGRectMake(0, 0, 1024, 768)];
//                        [splashImage setImage:[UIImage imageNamed:@"Default-Landscape.png"]];
//                        [self.tabBarController.view addSubview:splashImage];
//                        [act startAnimating];
//                        [splashImage addSubview:act];
//                        timer=[NSTimer scheduledTimerWithTimeInterval:30 target:self selector:@selector(RemovingSplash) userInfo:nil repeats:NO];
//                        [self startDistrictfeedstore];
//                        
//                    }

                }
            }
            else{
                NSURLRequest *request=[NSURLRequest requestWithURL:[NSURL fileURLWithPath:HTMLPath]];

                [[[self.scrollView subviews] objectAtIndex:page] loadRequest:request];

            }

        }
    }
    //NSLog(@"scrollview did scroll");

}





- (BOOL)webView:(UIWebView *)webView1 shouldStartLoadWithRequest:(NSURLRequest *)request navigationType:(UIWebViewNavigationType)navigationType{
    if (webView1==AD_webview) {


    }else{
        NSString *requestString = [[request URL] absoluteString];
       if ([requestString hasPrefix:@"mb::"])
         {
            NSArray *components = [requestString componentsSeparatedByString:@"::"];
             NSString *functionCall = [[[components objectAtIndex:1] componentsSeparatedByString:@"****"] objectAtIndex:0];
             NSString *args = [[[components objectAtIndex:1] componentsSeparatedByString:@"****"] objectAtIndex:1];
                args = [args stringByReplacingOccurrencesOfString:@"$" withString:@"'"];
             args = [args stringByReplacingPercentEscapesUsingEncoding:NSUTF8StringEncoding];


             [[NSNotificationCenter defaultCenter] postNotificationName:functionCall object:args];


             return NO;
         }
    }
}
Lucas Eduardo
  • 11,014
  • 5
  • 42
  • 48
shwetha p
  • 165
  • 9

1 Answers1

1

A NaN means "Not a Number". You may also sometimes see inf, which stands for "infinity". This happens when floating point calculations result in an infinity or an undefined value. Usually it's the result of either a divide by 0 error or an uninitialized variable. It means that at some point, you're setting your CALayer's position to an invalid floating point value. You can check values for NaNs by calling the standard C macro isnan(), though according to this page, it's not portable. FWIW, I've had good luck using it. (There's also an isinf() macro for checking for infinities.) You might also have luck using the static analyzer to see if you have any uninitialized variables. (Or turn on the compiler warning for uninitialized variables if it's not already on.)

Community
  • 1
  • 1
user1118321
  • 23,821
  • 4
  • 52
  • 78
  • :i printed all calculation it seems all are good not any nil or inf or nan – shwetha p Sep 06 '13 at 03:52
  • Perhaps you have a CALayer where you haven't initialized it fully? [Here's a similar question](http://stackoverflow.com/questions/11533120/how-to-solve-calayerinvalidgeometry-reason-calayer-position-contains-nan-n) that someone else fixed. Perhaps their answers will explain it better? – user1118321 Sep 06 '13 at 03:54
  • what is this calayer? – shwetha p Sep 06 '13 at 03:56
  • It's a Core Animation Layer. Sorry, from the error, I assumed you were directly using Core Animation. Maybe something you're using is invoking it on your behalf? – user1118321 Sep 06 '13 at 03:57
  • 1
    any way to detect from wer its coming? – shwetha p Sep 06 '13 at 04:10