I have the test case reproduct the error, and I post the code here:
#import "mySceneTest.h"
@implementation Scene1
-(id) init
{
// NSLog(@"Scene1 init ");
if (!(self=[super init] )) return nil;
MultiplexLayer *layers=[MultiplexLayer layerWithLayers: [Layer1 node], [Layer2 node], nil];
[self addChild: layers z: 1];
return self;
}
-(void) dealloc
{
NSLog(@"Scene1 dealloc");
[super dealloc];
}
@end
@implementation Layer1
-(id) init
{
if (!(self=[super init] )) return nil;
MenuItemFont *item1 = [MenuItemFont itemFromString: @"replaceScene" target:self selector:@selector(onReplaceScene:)];
MenuItemFont *item2 = [MenuItemFont itemFromString: @"switch to layer2" target:self selector:@selector(layerSwitch:)];
item2.tag = 1;
Menu *menu = [Menu menuWithItems: item1, item2, nil];
[menu alignItemsVertically];
[self addChild: menu];
[self schedule:@selector(testDealloc:)]; //this cause the bug
return self;
}
-(void) testDealloc:(ccTime) dt
{
// [self unschedule:_cmd];
}
-(void) layerSwitch: (id) sender
{
[(MultiplexLayer *)parent switchTo: [sender tag]];
}
-(void) onReplaceScene:(id) sender
{
[[Director sharedDirector] replaceScene: [Scene1 node] ];
}
-(void) dealloc
{
NSLog(@"layer1 dealloc");
[super dealloc];
}
@end
@implementation Layer2
-(id) init
{
if (!(self=[super init] )) return nil;
MenuItemFont *item1 = [MenuItemFont itemFromString: @"replaceScene" target:self selector:@selector(onReplaceScene:)];
MenuItemFont *item2 = [MenuItemFont itemFromString: @"switch to layer1" target:self selector:@selector(layerSwitch:)];
item2.tag = 0;
Menu *menu = [Menu menuWithItems: item1, item2, nil];
[menu alignItemsVertically];
[self addChild: menu];
return self;
}
-(void) layerSwitch: (id) sender
{
[(MultiplexLayer *)parent switchTo: [sender tag]];
}
-(void) onReplaceScene:(id) sender
{
[[Director sharedDirector] replaceScene: [Scene1 node] ];
}
-(void) dealloc
{
NSLog(@"layer2 dealloc");
[super dealloc];
}
@end
// CLASS IMPLEMENTATIONS
@implementation AppController
- (void) applicationDidFinishLaunching:(UIApplication*)application
{
// Init the window
window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
[window setUserInteractionEnabled:YES];
[window setMultipleTouchEnabled:NO];
// must be called before any othe call to the director
// [Director useFastDirector];
// before creating any layer, set the landscape mode
[[Director sharedDirector] setDeviceOrientation: CCDeviceOrientationLandscapeRight];
// attach the OpenGL view to a window
[[Director sharedDirector] attachInView:window];
// show FPS
[[Director sharedDirector] setDisplayFPS:YES];
// frames per second
[[Director sharedDirector] setAnimationInterval:1.0/60];
// Default texture format for PNG/BMP/TIFF/JPEG/GIF images
// It can be RGBA8888, RGBA4444, RGB5_A1, RGB565
// You can change anytime.
[Texture2D setDefaultAlphaPixelFormat:kTexture2DPixelFormat_RGBA8888];
Scene1 *scene = [Scene1 node];
[window makeKeyAndVisible];
[[Director sharedDirector] runWithScene: scene];
}
// getting a call, pause the game
-(void) applicationWillResignActive:(UIApplication *)application
{
[[Director sharedDirector] pause];
}
// call got rejected
-(void) applicationDidBecomeActive:(UIApplication *)application
{
[[Director sharedDirector] resume];
}
// purge memroy
- (void)applicationDidReceiveMemoryWarning:(UIApplication *)application {
[[TextureMgr sharedTextureMgr] removeAllTextures];
}
// next delta time will be zero
-(void) applicationSignificantTimeChange:(UIApplication *)application
{
[[Director sharedDirector] setNextDeltaTimeZero:YES];
}
- (void) dealloc
{
[window release];
[super dealloc];
}
@end
I think I should open an issue http://code.google.com/p/cocos2d-iphone/issues/detail?id=466