Projects > cpp > Issues > Bug #3295

We are migrating issue tracker of Cocos2d-x Project to Github, please create new issue there. Thanks.

Create Issue on Github

Invalid OpenGL Surface in Rare Scenario (Android - pre JellyBean)

Bug #3295 [Closed]
Sheado 2013-11-28 02:05 . Updated about 2 years ago


In some cases the GLSurfaceView can fail to be re-created. The best way to reproduce this is to launch another activity while your activity is starting (I am doing this to launch pre-roll ads in my case). One the bug occurs you get a black screen and the only way to recover from it is to press the back button, then re-enter (note: home button doesn’t fix it).

Here’s the error you get:

11-16 16:32:06.991: E/GLSurfaceView(6652): eglCreateWindowSurface
11-16 16:32:06.991: E/GLSurfaceView(6652): java.lang.IllegalArgumentException: Make sure the SurfaceView or associated SurfaceHolder has a valid Surface
11-16 16:32:06.991: E/GLSurfaceView(6652):     at Method)
11-16 16:32:06.991: E/GLSurfaceView(6652):     at
11-16 16:32:06.991: E/GLSurfaceView(6652):     at android.opengl.GLSurfaceView$DefaultWindowSurfaceFactory.createWindowSurface(
11-16 16:32:06.991: E/GLSurfaceView(6652):     at android.opengl.GLSurfaceView$EglHelper.createSurface(
11-16 16:32:06.991: E/GLSurfaceView(6652):     at android.opengl.GLSurfaceView$GLThread.guardedRun(
11-16 16:32:06.991: E/GLSurfaceView(6652):     at android.opengl.GLSurfaceView$

On stackoverflow is a post that could explain this: [[]]
I tried this solution out and it worked fine. Basically I back-ported GLSurfaceView from Android Level 19 and had Cocos2dxGLSurfaceView extend that version of GLSurfaceView. I also had to make the following change:

>                         if (mEglHelper.createSurface()) {
< //                                mFinishedCreatingEglSurface = true;
< //                                mSurfaceIsBad = true;
< //                                sGLThreadManager.notifyAll();
<                                 sGLThreadManager.wait();
>                                 mFinishedCreatingEglSurface = true;
>                                 mSurfaceIsBad = true;
>                                 sGLThreadManager.notifyAll();
<                               Thread.sleep( 250 );
<                         GLSurfaceView19 view = mGLSurfaceViewWeakRef.get();

This fixes the problem for me. Unfortunately the GLSurfaceView from level 19 is incompatible with Android 2.2 - so now I’m looking into backporting an older version.

Has anybody experienced this issue? Any better ideas for fixing this?
Thanks 2014-10-08 02:46

Redmine issue system is closed, we are using github issue system instead.

This issue was moved to

Atom PDF

Start date:2013-11-28
Due date:
% Done:


Target version:-

Sign up for our newsletter to keep up with the latest developments, releases and updates for Cocos2d-x.