I'm using cocos2d and ran into the following problem: The first time I initialize a scene I start with:
[[CCDirector sharedDirector] runWithScene: [MenuScene node]];
When switching between scenes, I always use:
[[CCDirector sharedDirector] replaceScene:[SceneName node]];
This works fine, I'm able to switch from the MenuScene to the GameScene, then to the GameOverScene and then back, to the MenuScene. But when I switch to the GameScene again, then to the GameOverScene again and try to switch to the MenuScene for the 2nd time (3rd time, if you count the initial runWithScene call) the app crashes and I get the error message:
*** -[EAGLView swapBuffers]: message sent to deallocated instance 0x9614f80
sharedlibrary apply-load-rules all
From what I've read, there should exist at least one scene at all times (which should be the case here?). I also tried to leave the initial scene untouched by using pushScene for all other scenes and popScene at the end to go back to the MenuScene, but I'm getting the same error this way, also on the 2nd run.
My implementation of the MenuScene looks as follows:
@implementation MenuScene
@synthesize menuLayer = _menuLayer;
- (id)init {
if ((self = [super init])) {
self.menuLayer = [MenuLayer node];
[self addChild:_menuLayer];
}
return self;
}
- (void)dealloc {
[_menuLayer release];
_menuLayer = nil;
[super dealloc];
}
@end