I'm building a Cocos2D game in which after two certain sprites collide (by simple bounding box technique), I call
[[CCDirector sharedDirector] replaceScene:gameOverScene];
to change to the game over scene.
Once it initializes the game over scene with everything in it, the game crashes and goes to this method in ccArray.m
class:
void ccArrayRemoveAllObjects(ccArray *arr)
{ while( arr->num > 0 )
CC_ARC_RELEASE(arr->arr[--arr->num]);
}
with the message: Thread 1: Program received signal: "EXC_BAD_ACCESS".
I tried to debug using breakpoints and figured out that once my gameOver scene gets initialized and ready to display, the dealloc
method in the previous class (the gameplay class, which called the replace scene) gets called and after which it throws this error.
My update
method:
-(void)update:(ccTime)dt
{
if (CGRectIntersectsRect(plane.boundingBox, enemy.boundingBox)) {
CCScene *gameOverScene = [GameOverLayer sceneWithWon:NO];
[[CCDirector sharedDirector] replaceScene:gameOverScene];
} }
My dealloc
method:
- (void) dealloc
{
[super dealloc];
[_monsters release];
_monsters = nil;
[mole release];
mole = nil;
[text release];
text = nil;
[mBG1 release];
mBG1 = nil;
[mBG2 release];
mBG2 = nil; }
I have no clue why this is happening. Please help.
Thanking you in anticipation.