7

When trying to press the back button quickly during launching some Activities with GLSurfaceView, eglCreateWindowSurface fails with java.lang.IllegalArgumentException.

I got the following errors:

10-08 18:05:36.490: E/GLSurfaceView(3440): eglCreateWindowSurface
10-08 18:05:36.490: E/GLSurfaceView(3440): java.lang.IllegalArgumentException: Make sure the SurfaceView or associated SurfaceHolder has a valid Surface
10-08 18:05:36.490: E/GLSurfaceView(3440): at com.google.android.gles_jni.EGLImpl._eglCreateWindowSurface(Native Method)
10-08 18:05:36.490: E/GLSurfaceView(3440): at com.google.android.gles_jni.EGLImpl.eglCreateWindowSurface(EGLImpl.java:90)
10-08 18:05:36.490: E/GLSurfaceView(3440): at android.opengl.GLSurfaceView$DefaultWindowSurfaceFactory.createWindowSurface(GLSurfaceView.java:798)
10-08 18:05:36.490: E/GLSurfaceView(3440): at android.opengl.GLSurfaceView$EglHelper.createSurface(GLSurfaceView.java:1065)
10-08 18:05:36.490: E/GLSurfaceView(3440): at android.opengl.GLSurfaceView$GLThread.guardedRun(GLSurfaceView.java:1433)
10-08 18:05:36.490: E/GLSurfaceView(3440): at android.opengl.GLSurfaceView$GLThread.run(GLSurfaceView.java:1216)

These activities didn't invoke GL operations before SurfaceHolder.Callback.surfaceCreated or after SurfaceHolder.Callback.surfaceDestroyed.

Has anyone else run into this, and what's the solution?

Thanks for any advance.

Dalinaum
  • 1,142
  • 13
  • 18

2 Answers2

12

Switching between multiple Activities quickly torn window surface down.

I patched GLSurfaceView.guardedRun() to avoid race condition of GLSurfaceView

from:

                if (createEglSurface) {
                    if (LOG_SURFACE) {
                        Log.w("GLThread", "egl createSurface");
                    }
                    gl = (GL10) mEglHelper.createSurface(getHolder());
                    if (gl == null) {
                        // Couldn't create a surface. Quit quietly.
                        break;
                    }
                    sGLThreadManager.checkGLDriver(gl);
                    createEglSurface = false;
                }

to:

                if (createEglSurface) {
                    if (LOG_SURFACE) {
                        Log.w("GLThread", "egl createSurface");
                    }
                    gl = (GL10) mEglHelper.createSurface(getHolder());
                    if (gl == null) {
                        // If we escape, GLThread ends up. Don't escape.
                        continue;
                    }
                    sGLThreadManager.checkGLDriver(gl);
                    createEglSurface = false;
                }

It looks to me like this problem was fixed in JellyBean.

Dalinaum
  • 1,142
  • 13
  • 18
  • Good catch, thanks! I ended up backporting the whole class from Jelly Bean, for lack of any simple way to patch the one line. – usethe4ce Nov 07 '12 at 22:51
  • 1
    How could you patch that one line? I got same problem. Could you please give me some hints. Thank you very much. – AmyWuGo May 23 '13 at 10:30
  • @AmyWuGo - add this file(https://gist.github.com/dalinaum/3890965) to your project. – Dalinaum May 24 '13 at 09:45
  • 1
    @Dalinaum Thank you very much. I tried your source, and the frequency of the bug became lower, but not disappear completely. I think there mush be some other bugs in my app. Thanks. – AmyWuGo May 27 '13 at 03:13
  • @AmyWuGo There are some bugs on SurfaceView until JB. Check newest SurfaceView. It will be of help to you. – Dalinaum May 27 '13 at 15:49
1

I had the same problem and fixed it by setting a callback for surfaceDestroyed and calling super.surfaceDestroyed.

glSurfaceView = new GLSurfaceView(context) {
    public void surfaceDestroyed(SurfaceHolder holder) {
        super.surfaceDestroyed(holder);
    }
};
codeNinja
  • 1,442
  • 3
  • 25
  • 61