Sharing the EGL2.0 context between 2 GLSurfaceViews caused EGL_BAD_ACCESS on Android tablets

Shu Sang picture Shu Sang · Jan 13, 2012 · Viewed 7.5k times · Source

I try to share EGL context bwteen 2 GLSurfaceViews by following code:

createContext(EGL10 egl, EGLDisplay display, EGLConfig eglConfig) {
    EGLContext shared = ...; // a cached egl context
    int[] attrib_list = { EGL_CONTEXT_CLIENT_VERSION, 2, EGL10.EGL_NONE };
    EGLContext context = egl.eglCreateContext(display, eglConfig, shared == null ? EGL10.EGL_NO_CONTEXT : shared,
        attrib_list);
    return context;
  }
}

The code works on most of the android phones (OS>=2.2) but failed on all the tested tablets.

01-12 18:33:35.381: E/AndroidRuntime(12171): FATAL EXCEPTION: GLThread 11

01-12 18:33:35.381: E/AndroidRuntime(12171): java.lang.RuntimeException: eglMakeCurrent failed: EGL_BAD_ACCESS

01-12 18:33:35.381: E/AndroidRuntime(12171): at android.opengl.GLSurfaceView$EglHelper.throwEglException(GLSurfaceView.java:1146)

Since I declared the LOCAL_LDLIBS: = -lGLESv2, the EGL is a 2.0 context.

Why it failed on tablets(xoom, galaxy, lg, sony, etc)

Any insight is appreciated.

Answer

Romain Guy picture Romain Guy · Jan 13, 2012

Two possible reasons for this failure (from the EGL spec):

  • If ctx is current to some other thread, or if either draw or read are bound to contexts in another thread, an EGL_BAD_ACCESS error is generated.
  • If binding ctx would exceed the number of current contexts of that client API type supported by the implementation, an EGL_BAD_ACCESS error is generated.

It could also be that the GPU you are using on tablets does not support shared context.