Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

eglCreateWindowSurface fails with java.lang.IllegalArgumentException

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.

like image 207
Dalinaum Avatar asked Oct 12 '12 08:10

Dalinaum


2 Answers

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.

like image 152
Dalinaum Avatar answered Oct 02 '22 07:10

Dalinaum


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);
    }
};
like image 26
codeNinja Avatar answered Oct 02 '22 09:10

codeNinja