Hi guys! We get thousands of crashes in our app as follows:
I am in no way an expert in OpenGl and rendering but i believe the problem happens when multiple gl contexts are involved. We verified that this crash happens after playable rewarded videos appear on screen and are closed and cocos2d-x is trying to continue rendering. I guess this was also a problem of the past in this method:
-(void) doCaller: (id) sender{
if (isAppActive) {
cocos2d::Director* director = cocos2d::Director::getInstance();
EAGLContext* cocos2dxContext = [(CCEAGLView*)director->getOpenGLView()->getEAGLView() context];
if (cocos2dxContext != [EAGLContext currentContext])
glFlush();
[EAGLContext setCurrentContext: cocos2dxContext];
CFTimeInterval dt = ((CADisplayLink*)displayLink).timestamp - lastDisplayTime;
lastDisplayTime = ((CADisplayLink*)displayLink).timestamp;
director->mainLoop(dt);
}
}
As i see we check if current context is cocos2d-x and flush it before setting the context. Is there any other improvement that can be done in this function to safeguard it further?
- Will it make any difference using glFinish instead of glFlush?
- Will it make any difference to getEAGLView after the glFlush?
I am asking this becasue this fix was originated from cocos crashed due to opengl context conflict when multiple contexts coexisted · Issue #16873 · cocos2d/cocos2d-x · GitHub in which the solution proposed was different:
-(void) doCaller: (id) sender
{
if (isAppActive) {
cocos2d::Director* director = cocos2d::Director::getInstance();
if([EAGLContext currentContext] != [(CCEAGLView*)director->getOpenGLView()->getEAGLView() context])
{
glFinish();
[EAGLContext setCurrentContext: [(CCEAGLView*)director->getOpenGLView()->getEAGLView() context]];
}
director->mainLoop();
}
}
Any OpenGl/Cocos2d-x experts please help so that we can solve for good this issue.