Ah Wen
Ah Wen

Reputation: 115

EXC_BAD_ACCESS using CCGLView when Home pressed

I use CCGLView in cocos2d2.0 to work with cocoa Touch. But my application will crash when I press home button. The error occured in CCGLView swapBuffers method:

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

The stack is:

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

6-[CCGlView swapBuffers]

7-[CCDirectorIOS drawScene]

8-[CCDirectorDisplayLink mainLoop:]

.....

By the way, I do pause the director at delegate method:

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

    [[CCDirector sharedDirector] pause];
}

Any ideas? Thanks.

Upvotes: 7

Views: 1044

Answers (2)

Arvind Kumar
Arvind Kumar

Reputation: 2411

I resolved this issue by pausing the animation in the background in the AppDelegate

- (void)applicationDidEnterBackground:(UIApplication *)application
{
    [_glView stopAnimation];
}

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

Upvotes: 0

Kyujin Kim
Kyujin Kim

Reputation: 71

my solution

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

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

Upvotes: 7

Related Questions