Sunday, 24 January 2021

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

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. This occurs only on some devices and all of them are on Android 7 Nougat.

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)

I don't know how to fix this error. 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();
    }
}


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

No comments:

Post a Comment