Home按下时使用CCGLView的EXC_BAD_ACCESS

时间:2013-10-08 06:36:08

标签: iphone ios cocos2d-iphone

我在cocos2d2.0中使用CCGLView来处理cocoa Touch。 但是当我按下主页按钮时,我的应用程序会崩溃。 CCGLView swapBuffers方法中出现错误:

if(![_context presentRenderbuffer:GL_RENDERBUFFER]) ------- EXC_BAD_ACCESS

堆栈是:

5:EAGLContext_presentRenderbuffer(EAGleContext *,objc_selectorr *,unsigned int)

6- [CCGlView swapBuffers]

7- [CCDirectorIOS drawScene]

8- [CCDirectorDisplayLink mainLoop:]

.....

顺便说一句,我确实按照委托方式暂停导演:

- (void)applicationDidEnterBackground:(UIApplication *)application
{

    [[CCDirector sharedDirector] pause];
}

有什么想法吗?感谢。

2 个答案:

答案 0 :(得分:7)

我的解决方案

- (void)applicationDidEnterBackground:(UIApplication *)application
{
    [[CCDirector sharedDirector] pause];   
    [[CCDirector sharedDirector] stopAnimation]; // Add
}

- (void)applicationWillEnterForeground:(UIApplication *)application
{
    [[CCDirector sharedDirector] resume];   
    [[CCDirector sharedDirector] startAnimation]; // Add
}

答案 1 :(得分:0)

我通过在AppDelegate

中暂停动画来解决此问题
- (void)applicationDidEnterBackground:(UIApplication *)application
{
    [_glView stopAnimation];
}

- (void)applicationWillEnterForeground:(UIApplication *)application
{
    [_glView startAnimation];
}