Update text on CCLabelTFF end in bad access?

Posted by TheDeveloper on Stack Overflow See other posts from Stack Overflow or by TheDeveloper
Published on 2012-06-10T22:35:22Z Indexed on 2012/06/10 22:40 UTC
Read the original article Hit count: 164

I'm doing a little game in Coco2D and I have a countdown clock Note: As I am just trying to fix a bug, I am not working on cleanup so the timer can stop, etc. Here is my code I'm using to setup the label and start the timer:

timer = [CCLabelTTF labelWithString:@"10.0000" fontName:@"Helvetica" fontSize:20]; 
        timerDisplay = timer;
        timerDisplay.position = ccp(277,310);
        [self addChild:timerDisplay];
        timeLeft = 10;

        timerObject = [NSTimer scheduledTimerWithTimeInterval:0.1 target:self selector:@selector(updateTimer) userInfo:nil repeats:YES];

Note: timeLeft is a double

This is updateTimers's code:

 -(void)updateTimer {
         NSLog(@"Got Called!");

         timeLeft = timeLeft -0.1;
     [timer setString:[NSString stringWithFormat:@"%f",timeLeft]];
       timerDisplay = timer;
         timerDisplay.position = ccp(277,310);
         [self removeChild:timerDisplay cleanup:YES];
         //[self addChild:timerDisplay];  
       if (timeLeft <= 0) {
             [timerObject invalidate];
         }     

     }

When I run this I toggle between crashing on this this: [timer setString:[NSString stringWithFormat:@"%f",timeLeft]]; and in the green arrow thing it gives Thread 1: EXEC_BAD_ACCESS (code=2, address=0x8) and 0x197a7ff: movl 16(%edi), %esi and in the green arrow thing it gives Thread 1: EXEC_BAD_ACCESS (code=2, address=0x8)

© Stack Overflow or respective owner

Related posts about cocos2d-iphone

Related posts about exc-bad-access