Getting GPU Information Programatically sometimes give "createcontext failed egl_bad_alloc" error

Viewed 257

I am trying to obtain the GPU information programmatically. Actually my code works on many devices. But firebase shows an error on some devices.

Error is this:

Fatal Exception: java.lang.RuntimeException: createContext failed: EGL_BAD_ALLOC
   at android.opengl.GLSurfaceView$EglHelper.throwEglException(GLSurfaceView.java:1209)
   at android.opengl.GLSurfaceView$EglHelper.throwEglException(GLSurfaceView.java:1200)
   at android.opengl.GLSurfaceView$EglHelper.start(GLSurfaceView.java:1050)
   at android.opengl.GLSurfaceView$GLThread.guardedRun(GLSurfaceView.java:1410)
   at android.opengl.GLSurfaceView$GLThread.run(GLSurfaceView.java:1257)

This occurs only on some devices and all of them are on Android 7 Nougat.

Can anyone guide me on fixing this error?

Here's my code.

public class SplashActivity extends Activity implements GLSurfaceView.Renderer {
private final Globals globals = Globals.getInstance();
private GLSurfaceView glSurfaceView;

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_splash);

    TextView txtGPUsupport = findViewById(R.id.txtGPUsupport);
    txtGPUsupport.setText(R.string.GPUVendor);
    glSurfaceView = new GLSurfaceView(this);
    glSurfaceView.setRenderer(this);
    ((ViewGroup) txtGPUsupport.getParent()).addView(glSurfaceView);
}

@Override
protected void onPause() {
    super.onPause();
    if (glSurfaceView != null) {
        glSurfaceView.onPause();
    }
}

@Override
protected void onResume() {
    super.onResume();
    if (glSurfaceView != null) {
        glSurfaceView.onResume();
    }
}

@Override
public void onDrawFrame(GL10 gl) {

}

@Override
public void onSurfaceChanged(GL10 gl, int width, int height) {

}

@Override
public void onSurfaceCreated(GL10 gl, EGLConfig config) {
    try {
        runOnUiThread(() -> glSurfaceView.setVisibility(View.GONE));
        globals.setGpuRenderer(gl.glGetString(GL10.GL_RENDERER));
        globals.setGpuVendor(gl.glGetString(GL10.GL_VENDOR));
        globals.setGpuVersion(gl.glGetString(GL10.GL_VERSION));
    } catch (Exception ex) {
        ex.printStackTrace();
    }
}
0 Answers
Related