首页 > 解决方案 > 以编程方式获取 GPU 信息有时会给出“createcontext failed egl_bad_alloc”错误

问题描述

我正在尝试以编程方式获取 GPU 信息。实际上我的代码适用于许多设备。但是 firebase 在某些设备上显示错误。错误是这样的。这仅在某些设备上发生,并且所有设备都在 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)

我不知道如何解决这个错误。谁能指导我修复这个错误?

这是我的代码。

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();
    }
}

标签: javaandroidopengl-esgpu

解决方案


推荐阅读