views:

1753

answers:

1

I am using cocos2d 0.99.4 and Xcode 4.0. so, I changed my AppDelegate in this way according to the documentation and example given in 0.99.4 version.

- (void) applicationDidFinishLaunching:(UIApplication*)application
{
    window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
    [CCDirector setDirectorType:kCCDirectorTypeDisplayLink];
    CCDirector *director = [CCDirector sharedDirector];
    [director setDeviceOrientation:kCCDeviceOrientationLandscapeLeft];
    [director setAnimationInterval:1.0/60];
    [director setDisplayFPS:NO];
    EAGLView *glView = [EAGLView viewWithFrame:[window bounds]
                               pixelFormat:kEAGLColorFormatRGBA8            
                               depthFormat:GL_DEPTH_COMPONENT24_OES   
                    preserveBackbuffer:NO];

    [[CCDirector sharedDirector] setOpenGLView:glView];

    [window addSubview:glView];
    [window makeKeyAndVisible]; 

    [CCTexture2D setDefaultAlphaPixelFormat:kCCTexture2DPixelFormat_RGBA8888];
    gameLevel = [[NSUserDefaults standardUserDefaults] integerForKey:@"gameLevel"] ;
    gameLevel = 1;

    CCScene *scene = [CCScene node];
    CCLayer *layer = [GamewinScreen node];  
    [scene addChild :layer];

    [[CCDirector sharedDirector] runWithScene: scene];  

}  

//The method test1 is also in the app Delegate class.

 -(void)test1
{

    [[CCDirector sharedDirector] end];
    [[CCDirector sharedDirector] setOpenGLView:[[window subviews] objectAtIndex:0]];    

    CCScene *Scene = [CCScene node];
    CCLayer *Layer = [OpeningScreen node];

    [Scene addChild:Layer]; 

    [[CCDirector sharedDirector] runWithScene: Scene];
}

In GameWinScreen I have a selector @selector(goToFirstScreen),

-(void)goToFirstScreen:(id)sender
{
    [MY_DELEGATE performSelector:@selector(test1) withObject:nil afterDelay:1.0];
 }   

After playing the game for 50 minutes and more I am getting

Received memory warning. Level=1  

for more than 10 times and then
Received memory warning. Level=2

and the application is crashing. giving the following message

Program received signal:  “0”.
Data Formatters temporarily unavailable, will re-try after a 'continue'. (Unknown error loading shared library "/Developer/usr/lib/libXcodeDebuggerSupport.dylib")

alt text

alt text

+1  A: 

This is cocos2d telling you that you are doing something wrong. You are calling setDirectorType on the director in goToFirstScreen, but the second time you call it there is already a director. I'm not sure why you are restarting the director. Why not just replace the scene:

-(void)goToFirstScreen:(id)sender
{
    CCScene *Scene = [CCScene node];
    CCLayer *Layer = [OpeningScreen node];
    [Scene addChild:Layer];
    [[CCDirector sharedDirector] replaceScene:Scene];
}   
Colin Gislason
@colin, I used the replace scene first, but when I played the game for more than 50 minutes continuously it was giving the Memory Warning Level 1 and then Memory Warning Level 2 and then crashing.So, I thought of end the CCDirector and restart again.Thank you.
srikanth rongali
You are leaking memory, restarting the director will not help any more than replacing the scene because your 'OpeningScreen' layer is the only object of yours that it is retaining. Try running the Leaks instrument to find out what memory you are leaking.
Colin Gislason
@Colin, i checked with the leaks tool. It is showing some leaks. The leaks are in CA::DisplayLink::dispatch. when I clicked on it is not showing the program. I have uploaded the images of leaks. Can you look at them please.Thank you.
srikanth rongali
You'll have to explore leaks a bit to figure that out. Looks like you're leaking a few different cocos2d classes, among others. Try using the extended detail view as shown in this tutorial: http://www.mobileorchard.com/find-iphone-memory-leaks-a-leaks-tool-tutorial/
Colin Gislason
Thanks Colin, I got fixed it. I used the replaceScene instead of the ending director. The problem is not in replaceScene as you said. It was in the memory release. I did not release some objects memory. Now I released it. And every thing is fine till now.Thank you.
srikanth rongali