Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Open GL Bad Config Error on Samsung S4

I am getting the following error on Samsung S4

10-21 16:25:44.100: E/AndroidRuntime(29778): FATAL EXCEPTION: GLThread 11320
10-21 16:25:44.100: E/AndroidRuntime(29778): Process: <bundle ID>, PID: 29778
10-21 16:25:44.100: E/AndroidRuntime(29778): java.lang.RuntimeException: createContext failed: EGL_BAD_CONFIG
10-21 16:25:44.100: E/AndroidRuntime(29778): at android.opengl.GLSurfaceView$EglHelper.throwEglException(GLSurfaceView.java:1201)
10-21 16:25:44.100: E/AndroidRuntime(29778): at android.opengl.GLSurfaceView$EglHelper.throwEglException(GLSurfaceView.java:1192)
10-21 16:25:44.100: E/AndroidRuntime(29778): at android.opengl.GLSurfaceView$EglHelper.start(GLSurfaceView.java:1042)
10-21 16:25:44.100: E/AndroidRuntime(29778): at android.opengl.GLSurfaceView$GLThread.guardedRun(GLSurfaceView.java:1409)
10-21 16:25:44.100: E/AndroidRuntime(29778): at android.opengl.GLSurfaceView$GLThread.run(GLSurfaceView.java:1248)

The error is because of :

this.setEGLContextFactory(new MyDefaultContextFactory());
this.setEGLConfigChooser(GL_RED_SIZE, GL_GREEN_SIZE, GL_BLUE_SIZE, GL_ALPHA_SIZE,
        GL_DEPTH_SIZE, 0);//<-this line
this.setDebugFlags(GLSurfaceView.DEBUG_CHECK_GL_ERROR
        | GLSurfaceView.DEBUG_LOG_GL_CALLS);
this.setPreserveEGLContextOnPause(true);
this.setEGLContextClientVersion(2);

Where the configuration passed is : 8,8,8,8,24

Moving the above line at the end works though. Whats the reason for this?

PS: The code works fine on Nexus5 or MotoG in either case. All devices running Kitkat 4.4.2

like image 990
vj9 Avatar asked Oct 22 '14 09:10

vj9


1 Answers

I don't see it clearly specified in the documentation, but from looking at the source code of GLSurfaceView, it really appears to be the case that setEGLContextClientVersion() must be called before setEGLConfigChooser().

Not copying any code because I'm not sure if that would violate copyrights, but you can follow along if you pull up the code link above:

  1. The overload of setEGLContextChooser() used in your code instantiates a new ComponentSizeChoser, with the specified sizes passed to the constructor.
  2. The constructor of ComponentSizeChooser invokes the base class constructor, passing the specified sizes packed into a config spec to the base constructor. The base class is BaseConfigChooser.
  3. The constructor of BaseConfigChooser invokes a private method filterConfigSpec(), passing it the config spec,
  4. filterConfigSpec() looks at the value of the mEGLContextClientVersion member variable, and uses it to determine the value of the EGL_RENDERABLE_TYPE attribute, which it adds to the config spec. It then returns the config spec with this additional attribute.
  5. Back in the BaseConfigChooser constructor, the modified config spec is assigned to a member variable.
  6. The config spec in this member variable is used later when the chooseConfig() method is called, where the actual configuration is selected.

mEGLContextClientVersion is the value set by setEGLContextClientVersion(). Therefore, the value set with this method will only be included in the configuration selection if setEGLContextClientVersion() is called before setEGLContextChooser().

Some devices provide configs that support both ES 1.X and ES 2.0/3.0, while others provide separate configs for 1.X and 2.0/3.0 support. This is most likely why the context creation succeeds with the calls in the "wrong" order on some devices, while it fails on others.

like image 121
Reto Koradi Avatar answered Sep 24 '22 04:09

Reto Koradi