1

To find a solution I have gone thru this similar link: TextureCache Error from Cocos2d when integrated into UIKit App but seems like it is dealing with this error in a different context..

Question: I have a UIKit project integrated with Cocos2d. When build, succeeds and runs but, at times crashes after receiving a memory warning with this error:

Assertion failure in -[CCTextureCache init], /Users/MyName/Documents/CSProject/CSProject/libs/cocos2d/CCTextureCache.m:90

Terminating app due to uncaught exception ‘NSInternalInconsistencyException’, reason: ‘Do not initialize the TextureCache before the Director’

The cocos2d scene is run from the view controller when a button is touched and the code is given below:

In ViewController.m

-(IBAction)overToCocos:(id)sender{
    CCDirector *director = [CCDirector sharedDirector];
    CCGLView *glView = [CCGLView viewWithFrame:CGRectMake(-100, -50, 480, 480)
                                   pixelFormat:kEAGLColorFormatRGBA8
                                   depthFormat:0];
    glView.opaque = NO;
    self.imagePicker.cameraOverlayView.userInteractionEnabled = YES;
    [self.imagePicker.cameraOverlayView insertSubview:glView atIndex:0];
    [self.imagePicker.cameraOverlayView bringSubviewToFront:glView];
    [director setView:glView];
    [director runWithScene:[HelloWorldLayer scene]];
}

Since the crash occurs after receiving a memory warning, I tried this

- (void)didReceiveMemoryWarning
{
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
    if ( [ CCDirector sharedDirector ].view != nil ){
        [[CCTextureCache sharedTextureCache] removeUnusedTextures];
    }

}

Also added this to AppDelegate's applicationDidReceiveMemoryWarning. But the crash still exists.. Please point me to the right direction to handle this error..

Thanks in advance!

Community
  • 1
  • 1
iSeeker
  • 776
  • 1
  • 8
  • 24
  • Enable exception breakpoint in Xcode. When the crash occurs, you'll get a call stack. Check each method in the call stack presented after the crash and you'll find the place initiating the texture cache. From there it should be simple to figure out why the texture cache is created before the director. – CodeSmile Aug 16 '13 at 15:52

0 Answers0