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 over 10 years ago

Hi,

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 com.google.android.gles_jni.EGLImpl._eglCreateWindowSurface(Native Method)
11-16 16:32:06.991: E/GLSurfaceView(6652):     at com.google.android.gles_jni.EGLImpl.eglCreateWindowSurface(EGLImpl.java:90)
11-16 16:32:06.991: E/GLSurfaceView(6652):     at android.opengl.GLSurfaceView$DefaultWindowSurfaceFactory.createWindowSurface(GLSurfaceView.java:798)
11-16 16:32:06.991: E/GLSurfaceView(6652):     at android.opengl.GLSurfaceView$EglHelper.createSurface(GLSurfaceView.java:1065)
11-16 16:32:06.991: E/GLSurfaceView(6652):     at android.opengl.GLSurfaceView$GLThread.guardedRun(GLSurfaceView.java:1433)
11-16 16:32:06.991: E/GLSurfaceView(6652):     at android.opengl.GLSurfaceView$GLThread.run(GLSurfaceView.java:1216)

On stackoverflow is a post that could explain this: [[http://stackoverflow.com/questions/12855103/eglcreatewindowsurface-fails-with-java-lang-illegalargumentexception]]
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()) {
1486,1489c1479,1481
< //                                mFinishedCreatingEglSurface = true;
< //                                mSurfaceIsBad = true;
< //                                sGLThreadManager.notifyAll();
<                                 sGLThreadManager.wait();
---
>                                 mFinishedCreatingEglSurface = true;
>                                 mSurfaceIsBad = true;
>                                 sGLThreadManager.notifyAll();
1491,1492d1482
<                               
<                               Thread.sleep( 250 );
1509c1499
<                         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

walzer@cocos2d-x.org 2014-10-08 02:46

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

This issue was moved to https://github.com/cocos2d/cocos2d-x/issues/8270

Atom PDF

Status:Closed
Start date:2013-11-28
Priority:Low
Due date:
Assignee:-
% Done:

0%

Category:android
Target version:-