Android – eglconfig on HTLC desire, which can be configured to suspend the device
I am implementing my own eglconfigchooser and passing it to seteglconfigchooser () to select the best available configuration for the current device according to my application requirements
More specifically, I am querying all available configurations and selecting the configuration with the maximum depth buffer size (and the one I want to have the maximum color depth between those with the same depth buffer size). The code wall is as follows:
@Override
public EGLConfig chooseConfig(EGL10 egl, EGLDisplay display)
{
//Querying number of configurations
int[] num_conf = new int[1];
egl.eglGetConfigs(display, null, 0, num_conf); //if configuration array is null it still returns the number of configurations
int configurations = num_conf[0];
//Querying actual configurations
EGLConfig[] conf = new EGLConfig[configurations];
egl.eglGetConfigs(display, conf, configurations, num_conf);
EGLConfig result = null;
for(int i = 0; i < configurations; i++)
{
Log.v("EGLConfigChooser", "Configuration #" + i );
print(egl, display, conf[i]);
result = better(result, conf[i], egl, display);
}
Log.v("EGLConfigChooser", "Chosen EGLConfig:");
print(egl, display, result);
return result;
}
/**
* Returns the best of the two EGLConfig passed according to depth and colours
* @param a The first candidate
* @param b The second candidate
* @return The chosen candidate
*/
private EGLConfig better(EGLConfig a, EGLConfig b, EGL10 egl, EGLDisplay display)
{
if(a == null) return b;
EGLConfig result = null;
int[] value = new int[1];
egl.eglGetConfigAttrib(display, a, EGL10.EGL_DEPTH_SIZE, value);
int depthA = value[0];
egl.eglGetConfigAttrib(display, b, EGL10.EGL_DEPTH_SIZE, value);
int depthB = value[0];
if(depthA > depthB)
result = a;
else if(depthA < depthB)
result = b;
else //if depthA == depthB
{
egl.eglGetConfigAttrib(display, a, EGL10.EGL_RED_SIZE, value);
int redA = value[0];
egl.eglGetConfigAttrib(display, b, EGL10.EGL_RED_SIZE, value);
int redB = value[0];
if(redA > redB)
result = a;
else if(redA < redB)
result = b;
else //if redA == redB
{
//Don't care
result = a;
}
}
return result;
}
(the print method outputs the eglconfig value to the logger)
Now that it seems to be working properly, it selects the following configuration:
01-30 18:57:04.424: VERBOSE/EGLConfigChooser(1093): Chosen EGLConfig:
01-30 18:57:04.424: VERBOSE/EGLConfigChooser(1093): EGL_RED_SIZE = 8
01-30 18:57:04.424: VERBOSE/EGLConfigChooser(1093): EGL_BLUE_SIZE = 8
01-30 18:57:04.424: VERBOSE/EGLConfigChooser(1093): EGL_GREEN_SIZE = 8
01-30 18:57:04.424: VERBOSE/EGLConfigChooser(1093): EGL_ALPHA_SIZE = 8
01-30 18:57:04.424: VERBOSE/EGLConfigChooser(1093): EGL_DEPTH_SIZE = 24
01-30 18:57:04.424: VERBOSE/EGLConfigChooser(1093): EGL_ALPHA_FORMAT = 24
01-30 18:57:04.424: VERBOSE/EGLConfigChooser(1093): EGL_ALPHA_MASK_SIZE = 0
01-30 18:57:04.424: VERBOSE/EGLConfigChooser(1093): EGL_STENCIL_SIZE = 8
The problem is that when using this configuration, the phone screen will turn green with purple artifacts (the scene should be black with a wooden table). It completely hangs and stops responding to any type of input. All I can do is terminate my process through the debugger. When I do so, the device will restart (?!)
Why does eglgetconfigs return configurations that cause such problems? Have any of you ever experienced something like this, or found a flaw in my code? I checked it carefully, but it looks good http://brandnewreality.com/blog/android-egl-querying-your-gl-driver (inspired by)
Thanks for your help.
resolvent:
Try adding:
getHolder().setFormat(PixelFormat.RGBA_8888);
After setting the GL configuration selector, for the surface constructor. Basically, I encountered a crash when selecting the format 8,8,8,0,0,0 (R8, G8, B8, A0, Z0, stencil0), until I added this line
Steve