'NSInternalInconsistencyException:不要在Director之前初始化TextureCache'

时间:2013-08-16 12:39:37

标签: ios cocos2d-iphone didreceivememorywarning cctexturecache

要找到解决方案,我已经通过这个类似的链接: TextureCache Error from Cocos2d when integrated into UIKit App 但似乎它在不同的背景下处理这个错误..

问题: 我有一个与Cocos2d集成的UIKit项目。在构建时,成功并运行但是,在收到内存警告之后,有时会因此错误而崩溃:

断言失败 - [CCTextureCache init],/ Uss / MyName / Files / CSProject / CSProject / libs / corpos2d / CCTextureCache.m:90

由于未捕获的异常'NSInternalInconsistencyException'而终止应用程序,原因:'不要在Director'之前初始化TextureCache

触摸按钮时会从视图控制器运行cocos2d场景,代码如下:

在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]];
}

由于在收到内存警告后发生崩溃,我尝试了这个

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

}

还将此添加到AppDelegate的applicationDidReceiveMemoryWarning中。 但崩溃仍然存在..请指出正确的方向来处理这个错误..

提前致谢!

0 个答案:

没有答案