Reputation: 4732
I'm creating a game, using cocos2d. Here is method, called when game creating:
- (void)createGame
{
GameScene *newScene = [[GameScene alloc] initWithController:self]; //subclass of CCScene
if ([CCDirector sharedDirector].runningScene)
[[CCDirector sharedDirector] replaceScene:newScene];
else
[[CCDirector sharedDirector] pushScene:newScene];
scene = newScene;
//some controllers for some layers of my scene
box2d = [[Box2DController alloc] initWithParent:self];
menu = [[MenuController alloc] initWithParent:self];
controls = ([[ControlsController alloc] initWithParent:self]);
self.controllers = [[NSArray alloc] initWithObjects:box2d, menu, controls, nil];
//some object, contains some parameters. rizeEvent tells about some event to all controllers. In this case, it sends pointer to worldState to all of them.
worldState = [[WorldState alloc] init];
EventArgs *eventArgs1 = [[EventArgs alloc] initWithSender:self params:worldState];
[self riseEvent:@"WorldStateUpdate" withArgs:eventArgs1];
}
I have a button, that destroys my world, and creates new one:
- (void)onExitPressedWithArgs:(EventArgs *)e
{
[self destroyGame];
[self createGame];
}
Here is 'destroyGame' method:
- (void)destroyGame
{
[box2d release];
[menu release];
[controls release];
[scene release];
[worldState release];
box2d = nil;
menu = nil;
controls = nil;
scene = nil;
worldState = nil;
[self.controllers release];
self.controllers = nil;
}
So, I'm launching my applications:
It crashes always in different parts of cade, but always with "EXC_BAD_ACCESS" exception.
Upvotes: 0
Views: 173
Reputation: 4215
Similar to Rishi's suggestion, but there's a problem with the initial assignment as well.
1) Replace this:
self.controllers = [[NSArray alloc] initWithObjects:box2d, menu, controls, nil];
with this:
controllers = [[NSArray alloc] initWithObjects:box2d, menu, controls, nil];
2) And this:
[self.controllers release];
self.controllers = nil;
with:
[controllers release];
controllers = nil;
Upvotes: 0
Reputation: 11839
remove [self.controllers release];
from destroyGame
method. As you are already calling self.controllers = nil;
which will do the required job for you.
Upvotes: 1