eglCreateWindowSurface fails with java.lang.IllegalArgumentException
Asked Answered
T

2

8

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.

Telesthesia answered 12/10, 2012 at 8:30 Comment(0)
T
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.

Telesthesia answered 15/10, 2012 at 8:2 Comment(5)
Good catch, thanks! I ended up backporting the whole class from Jelly Bean, for lack of any simple way to patch the one line.Sodium
How could you patch that one line? I got same problem. Could you please give me some hints. Thank you very much.Bibliography
@Bibliography - add this file(gist.github.com/dalinaum/3890965) to your project.Telesthesia
@Telesthesia 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.Bibliography
@Bibliography There are some bugs on SurfaceView until JB. Check newest SurfaceView. It will be of help to you.Telesthesia
U
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);
    }
};
Untwist answered 7/8, 2013 at 16:54 Comment(1)
My problem wass not same case. See also my answer. Thanks anyway, @codeNinja.Telesthesia

© 2022 - 2024 — McMap. All rights reserved.