 |
 |
|
 |
03-09-2010, 08:52 PM
|
#1 (permalink)
|
|
Registered Member
Join Date: Mar 2010
Posts: 5
|
Collision Error
In my app I have to objects colliding. When they do gives me the errors "Program received signals:'EXC_BAD_ACCESS'" and objc_msgSend.
Code:
- (void)checkcollision{
if(CGRectIntersectsRect(Object.frame, ballImage.frame)){
UIAlertView *alert = [[UIAlertView alloc]initWithTitle:@"Game Over, Score:" message:time.text delegate:nil cancelButtonTitle:@"Okay" otherButtonTitles:nil];
[alert show];
[alert release];
[myTicker invalidate];
pos = CGPointMake(0.0,0.0);
}
}
But when I remove the UIAlertView so the code is...
Code:
- (void)checkcollision{
if(CGRectIntersectsRect(Object.frame, ballImage.frame)){
[myTicker invalidate];
pos = CGPointMake(0.0,0.0);
}
}
I get the error "Program received signals:'SIGABRT'" and _kill
I've read that I'm getting the EXC_BAD_ACCESS and objc_msgSend because the Alert is being deallocated. But the only deallocation I have id the super dealloc at the end.
Thanks
-Oblivian Studios
|
|
|
03-09-2010, 08:59 PM
|
#2 (permalink)
|
|
iPhone SDK learner
Join Date: Feb 2010
Location: Illinois, USA
Posts: 346
|
Quote:
Originally Posted by OblivianStudios
In my app I have to objects colliding. When they do gives me the errors "Program received signals:'EXC_BAD_ACCESS'" and objc_msgSend.
Code:
- (void)checkcollision{
if(CGRectIntersectsRect(Object.frame, ballImage.frame)){
UIAlertView *alert = [[UIAlertView alloc]initWithTitle:@"Game Over, Score:" message:time.text delegate:nil cancelButtonTitle:@"Okay" otherButtonTitles:nil];
[alert show];
[alert release];
[myTicker invalidate];
pos = CGPointMake(0.0,0.0);
}
}
But when I remove the UIAlertView so the code is...
Code:
- (void)checkcollision{
if(CGRectIntersectsRect(Object.frame, ballImage.frame)){
[myTicker invalidate];
pos = CGPointMake(0.0,0.0);
}
}
I get the error "Program received signals:'SIGABRT'" and _kill
I've read that I'm getting the EXC_BAD_ACCESS and objc_msgSend because the Alert is being deallocated. But the only deallocation I have id the super dealloc at the end.
Thanks
-Oblivian Studios
|
i've gotten those errors when i test an object that = nil. make sure Object and ballImage do not = nil, and make sure you have allocated and init both.
|
|
|
03-09-2010, 10:40 PM
|
#3 (permalink)
|
|
Senior Member
iPhone Dev SDK Supporter
Join Date: Jul 2008
Location: San Mateo, CA (San Fran)
Posts: 3,070
|
If you comment out [myTicker invalidate], does it still crash? If so, you're probably invalidating the timer twice. I always set the timer to nil after invalidating it, since [nil invalidate] will do nothing.
|
|
|
03-10-2010, 05:01 PM
|
#4 (permalink)
|
|
Registered Member
Join Date: Mar 2010
Posts: 5
|
Quote:
Originally Posted by smasher
If you comment out [myTicker invalidate], does it still crash? If so, you're probably invalidating the timer twice. I always set the timer to nil after invalidating it, since [nil invalidate] will do nothing.
|
I invalidate the timer when I pause the game, but then restart it when I un-pasue it.
Pause
Code:
- (IBAction)stop{
[myTicker invalidate];
myTicker = nil;
startButton.hidden = FALSE;
stopButton.hidden = TRUE;
Object.hidden = TRUE;
NAME.hidden = TRUE;
pauseLabel.hidden = FALSE;
//startButton.alpha = 0.5;
time.alpha = 0.5;
timeLabelText.alpha = 0.5;
backgroundImage.alpha = 0.5;
pos = CGPointMake(0.0,0.0);
}
I've tried nullifying it after I invalidate it but it still doesn't work
Un - Pause
Code:
- (IBAction)start{
myTicker = [NSTimer scheduledTimerWithTimeInterval:.09 target:self selector:@selector(showActivity) userInfo:nil repeats:YES];
stopButton.hidden = FALSE;
startButton.hidden = TRUE;
Object.hidden = FALSE;
NAME.hidden = FALSE;
pauseLabel.hidden = TRUE;
time.alpha = 1.0;
timeLabelText.alpha = 1.0;
backgroundImage.alpha = 1.0;
pos = CGPointMake(7.0,3.5);
[NSTimer scheduledTimerWithTimeInterval:0.05 target:self selector:@selector (onTimer) userInfo:nil repeats:YES];
[self checkcollision];
}
Thanks
-Oblivian Studios
|
|
|
03-10-2010, 05:35 PM
|
#5 (permalink)
|
|
Senior Member
iPhone Dev SDK Supporter
Join Date: Jul 2008
Location: San Mateo, CA (San Fran)
Posts: 3,070
|
If you comment out [myTicker invalidate], does it still crash? That will let you know whether to continue down the myTicker path looking for errors, or go back an examine something else.
From the code you posted I can see that if the objects collide and then later you call the stop method, you wind up invalidating the timer a second time. That doesn't sound like your current problem, but still, that's why you should set the timer to nil after invalidating it.
|
|
|
03-10-2010, 06:19 PM
|
#6 (permalink)
|
|
Registered Member
Join Date: Mar 2010
Posts: 5
|
Quote:
Originally Posted by smasher
If you comment out [myTicker invalidate], does it still crash? That will let you know whether to continue down the myTicker path looking for errors, or go back an examine something else.
From the code you posted I can see that if the objects collide and then later you call the stop method, you wind up invalidating the timer a second time. That doesn't sound like your current problem, but still, that's why you should set the timer to nil after invalidating it.
|
Sorry I didn't answer your question in the first post but, yes if I comment out [myTicker invalidate]; when the objects collide it does work but the alert just keeps coming up.
Thanks
-Oblivian Studios
|
|
|
03-10-2010, 07:21 PM
|
#7 (permalink)
|
|
Senior Member
iPhone Dev SDK Supporter
Join Date: Jul 2008
Location: San Mateo, CA (San Fran)
Posts: 3,070
|
Okay, then setting the timer to nil after you invalidate it will probably stop that crash. It might be hiding a deeper problem of course; I'd add an NSLog at the top of checkCollision to see if it's still getting called after the timer is invalidated.
I see where you are calling checkCollision directly; I assume that checkCollision is also called somewhere down the chain from showActivity? And not from onTimer, right? If checkCollision is getting called from onTimer then you'll have a problem, because onTimer (and checkCollision) will keep getting called even though you invalidate myTicker.
Also, if you accidentally call "start" twice then you'll have a problem, because you'll have four timers (two calling, two calling onTimer) and you'll only have a pointer to one of them. One way to fix that would be to always invalidate myTicker before creating a new one.
Code:
//kill old timer
[myTicker invalidate];
//create new timer
myTicker = [NSTimer scheduledTimerWithTimeInterval:.09 target:self selector:@selector(showActivity) userInfo:nil repeats:YES];
|
|
|
 |
| Thread Tools |
|
|
| Display Modes |
Linear Mode
|
Posting Rules
|
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
HTML code is Off
|
|
|
|
» Advertisements |
» Online Users: 425 |
| 39 members and 386 guests |
| AdamSubach, aderrington, anubhab123, benoitr007, BrianSlick, caseysackett, Danneman, dev123, ErichGS, futurevilla216, Gambit, GreatWizard, gustavo7sexton, gw1921, HemiMG, HowEver, iSDK, Jeremy1026, joelhull, lifeCoder45, mattiahalter, melodizzzy, mriphoneman, newchucky, Ovidius, Piequanna, qilin, Racker, rendezvouscp, riq, Sega dude, socals, themathminister, timle8n1, tinrocket, Whitehk, ZunePod |
| Most users ever online was 965, 06-30-2010 at 04:26 AM. |
» Stats |
Members: 41,862
Threads: 49,770
Posts: 213,057
Top Poster: BrianSlick (3,139)
|
| Welcome to our newest member, futurevilla216 |
|