-1

My app crashes on CGRectIntersectsRect and I dont know what to do.
Here is my code :

if(CGRectIntersectsRect(player.frame,enemy.frame)) 
{
    loseViewController *controller = [[loseViewController alloc] initWithNibName:@"loseView" bundle:nil];                                        

    controller.modalTransitionStyle = UIModalTransitionStyleFlipHorizontal;
    [self presentModalViewController:controller animated:NO];   
    [controller release];
}
R.daneel.olivaw
  • 2,681
  • 21
  • 31
  • `player` or `enemy` might have been deallocated, could you check that ? –  Dec 22 '11 at 14:20
  • As @Vince says, probably one of those objects has been dealloc'd. Try enabling zombies which will help with determining that. See http://stackoverflow.com/questions/5386160/how-to-enable-nszombie-in-xcode for turning on zombies in Xcode 4. – mattjgalloway Dec 22 '11 at 14:34

1 Answers1

1

Expanding on @Vince's comment (I'm not sure why it wasn't an answer!) . . . .

Where does it crash if you do

CGRect playerRect = player.frame;
CGRect enemyRect = enemy.frame;
if (CGRectIntersectsRect(playerRect, enemyRect)) {

instead of

if(CGRectIntersectsRect(player.frame,enemy.frame)) {

That should tell you which (or both) object has been deallocated.

deanWombourne
  • 38,189
  • 13
  • 98
  • 110
  • Unless there's a bug in `CGRectIntersectsRect`. OK, highly unlikely, but worth checking with either zombies or your code first. I prefer the zombies approach personally as I think (in general) it should always be on during development. That and having a breakpoint on `objc_exception_throw`! – mattjgalloway Dec 22 '11 at 14:51
  • Then put a breakpoint on the first line and step through - that should tell you if it's `player` or `enemy` that's been dealloced. If you get to the CGRectIntersectsRect then tell us that the rects are. – deanWombourne Dec 22 '11 at 17:06
  • We're should I put the breakpoint and does my code look correct – jacobmac13 Dec 23 '11 at 10:40
  • That comment tells me you haven't tried what's in my question. Put the breakpoint on the first line of my original answer. – deanWombourne Dec 27 '11 at 16:24