Advertise Books Events Forum News Social Networking Support Us
Follow @iphonedevsdk on Twitter

sdkIQ for iPhone
($4.99)

Your First iPhone App
($1.99)

iPhone Code Generator
($9.99)

Dual Matches
($0.99)

Calcuccino Programmers' Calculator
($2.99)

SDKtoday
(free)

Want your application or service advertised on iPhone Dev SDK?

Go Back   iPhone Dev SDK Forum > iPhone SDK Development Forums > iPhone SDK Development

Reply
 
LinkBack Thread Tools Display Modes
Old 03-09-2010, 08:52 PM   #1 (permalink)
Registered Member
 
Join Date: Mar 2010
Posts: 5
Default 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
OblivianStudios is offline   Reply With Quote
Old 03-09-2010, 08:59 PM   #2 (permalink)
iPhone SDK learner
 
Join Date: Feb 2010
Location: Illinois, USA
Posts: 346
Default

Quote:
Originally Posted by OblivianStudios View Post
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.
Batman is offline   Reply With Quote
Old 03-09-2010, 10:40 PM   #3 (permalink)
Senior Member
iPhone Dev SDK Supporter
 
smasher's Avatar
 
Join Date: Jul 2008
Location: San Mateo, CA (San Fran)
Posts: 3,070
Default

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.
__________________
~~
-- Available Now: Dead Panic, a strategic zombie shooter!(iPhone)
-- New Blog Post: A Simple Observer Pattern for iPhone / Cocoa Games
smasher is offline   Reply With Quote
Old 03-10-2010, 05:01 PM   #4 (permalink)
Registered Member
 
Join Date: Mar 2010
Posts: 5
Default

Quote:
Originally Posted by smasher View Post
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
OblivianStudios is offline   Reply With Quote
Old 03-10-2010, 05:35 PM   #5 (permalink)
Senior Member
iPhone Dev SDK Supporter
 
smasher's Avatar
 
Join Date: Jul 2008
Location: San Mateo, CA (San Fran)
Posts: 3,070
Default

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.
__________________
~~
-- Available Now: Dead Panic, a strategic zombie shooter!(iPhone)
-- New Blog Post: A Simple Observer Pattern for iPhone / Cocoa Games
smasher is offline   Reply With Quote
Old 03-10-2010, 06:19 PM   #6 (permalink)
Registered Member
 
Join Date: Mar 2010
Posts: 5
Default

Quote:
Originally Posted by smasher View Post
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
OblivianStudios is offline   Reply With Quote
Old 03-10-2010, 07:21 PM   #7 (permalink)
Senior Member
iPhone Dev SDK Supporter
 
smasher's Avatar
 
Join Date: Jul 2008
Location: San Mateo, CA (San Fran)
Posts: 3,070
Default

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];
__________________
~~
-- Available Now: Dead Panic, a strategic zombie shooter!(iPhone)
-- New Blog Post: A Simple Observer Pattern for iPhone / Cocoa Games
smasher is offline   Reply With Quote
Reply

Bookmarks

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


» Advertisements
» Stats
Members: 41,862
Threads: 49,770
Posts: 213,057
Top Poster: BrianSlick (3,139)
Welcome to our newest member, futurevilla216
Powered by vBadvanced CMPS v3.1.0

All times are GMT -5. The time now is 07:04 PM.
Powered by vBulletin® Version 3.8.0
Copyright ©2000 - 2010, Jelsoft Enterprises Ltd.
Search Engine Friendly URLs by vBSEO 3.2.0