I'm working on an app and the code complies just fine but during runtime the app crashes with the following problem...
GDB: Program received signal: "SIGABRT"
AND SOMETIMES THIS ONE (with no change in code)
“EXC_BAD_ACCESS”
In the Debugger you can see what memory location that is coming from and where it's coming from.
Code:
[timer invalidate];
I've tried different things i've found online but can't seem to get this solved.
Here's the code snipit from where i think the problem is. Let me know if there is something really odd about what i'm doing or if there is a error...or a better way. Any help would be great...it's just frustrating at this point!
Code:
//METHOD TO DETECT MOVEMENT IN iPHONE
- (void)accelerometer:(UIAccelerometer *)acel didAccelerate:(UIAcceleration *)aceler {
if (fabsf(aceler.x) > 2 || fabsf(aceler.y) > 2 || fabsf(aceler.z) > 2)
{
//TEST STATEMENT
[label setText:@"You shook me!"];
//SET PROGRESS BAR TO 0
progressView.progress = 0.0;
//INITIALIZE TIMER - SELECTOR TO MOVE PROGRESS
timer = [NSTimer scheduledTimerWithTimeInterval:1.0 target:self selector:@selector(moveProgress) userInfo:nil repeats: YES];
}
}
-(void)moveProgress
{
progressView.progress = progressView.progress + 0.1;
if (progressView.progress == 0.5)
{
[progressLabel setText:@"That's a tough one..."];
}
if (progressView.progress == 1.0)
{
//END TIMER
[timer invalidate]; //PROBLEM????
//CREAT ARRAY FROM PLIST (IDENTICAL TO FLIPSIDE LOAD)
NSString *filePath = [[NSBundle mainBundle] pathForResource:@"answers" ofType:@"plist"];
//NSLog(filePath);
NSArray *array = [[NSArray alloc]initWithContentsOfFile:filePath];
self.answerList1 = array;
[array release];
// NSLog(answerList);
//STORE TOTAL ANSWER LIST COUNT
int numAnswers = [answerList1 count];
//RANDOM SELECT AN ARRAY INDEX
int randSelected = arc4random() % numAnswers;
//STORE THAT SELECTION AS A STRING (RANDOM PLIST ITEM)
NSString *selection = [answerList1 objectAtIndex:randSelected];
//OUTPUT THAT RANDOM SELECTION
[label setText:selection];
image1.hidden = NO;
progressView.hidden = YES;
[progressLabel setText:@""];
NSString *soundPath = [[NSBundle mainBundle] pathForResource:@"fortuneSound" ofType:@"wav"];
SystemSoundID soundID;
AudioServicesCreateSystemSoundID((CFURLRef)[NSURL fileURLWithPath:soundPath], &soundID);
AudioServicesPlaySystemSound (soundID);
}
}