【问题标题】:eglMakeCurrent failed EGL_BAD_ALLOCeglMakeCurrent 失败 EGL_BAD_ALLOC
【发布时间】:2015-05-22 09:40:53
【问题描述】:

我不断收到此错误报告

Fatal Exception: java.lang.IllegalStateException
eglMakeCurrent failed EGL_BAD_ALLOC
android.view.HardwareRenderer$GlRenderer.createSurface

在我在 Play 商店中的应用上。是什么导致了这次崩溃,如何解决?以下是完整的错误日志。

java.lang.IllegalStateException: eglMakeCurrent failed EGL_BAD_ALLOC
   at android.view.HardwareRenderer$GlRenderer.createSurface(HardwareRenderer.java:1354)
   at android.view.HardwareRenderer$GlRenderer.createEglSurface(HardwareRenderer.java:1241)
   at android.view.HardwareRenderer$GlRenderer.initialize(HardwareRenderer.java:1058)
   at android.view.ViewRootImpl.performTraversals(ViewRootImpl.java:1811)
   at android.view.ViewRootImpl.doTraversal(ViewRootImpl.java:1235)
   at android.view.ViewRootImpl$TraversalRunnable.run(ViewRootImpl.java:6472)
   at android.view.Choreographer$CallbackRecord.run(Choreographer.java:803)
   at android.view.Choreographer.doCallbacks(Choreographer.java:603)
   at android.view.Choreographer.doFrame(Choreographer.java:573)
   at android.view.Choreographer$FrameDisplayEventReceiver.run(Choreographer.java:789)
   at android.os.Handler.handleCallback(Handler.java:733)
   at android.os.Handler.dispatchMessage(Handler.java:95)
   at android.os.Looper.loop(Looper.java:157)
   at android.app.ActivityThread.main(ActivityThread.java:5356)
   at java.lang.reflect.Method.invokeNative(Method.java)
   at java.lang.reflect.Method.invoke(Method.java:515)
   at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1265)
   at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1081)
   at dalvik.system.NativeStart.main(NativeStart.java)

【问题讨论】:

  • 嘿,你找到解决方案了吗?
  • @OshaMahue Nope。我从来没有找到过。
  • @AlexKombo 您能告诉我们哪些设备出现此错误吗?看起来错误是特定于设备的,知道设备将有助于缩小范围。
  • 另外,您能否发布您的登陆活动的 onPause 和 onResume 方法。这可能是由某些设备上某些版本的 Android 中出现的竞争条件引起的

标签: android renderer android-hardware


【解决方案1】:

如果您查看EGL specification,此错误可能有多种原因。您的应用程序中的某些东西似乎导致其资源不足。规范声明如下:

3.7.3 绑定上下文和可绘制对象

... eglMakeCurrent 将 ctx 绑定到当前渲染线程和 draw 和 读取表面...

错误

...如果无法分配用于绘制和读取的辅助缓冲区,则 产生EGL_BAD_ALLOC错误...

要解决此问题,您可以检查应用程序的内存使用情况。有许多不同的技术可以调查您的应用程序的 ram 使用情况,some techniques are documented quite well in this guide.

This post还描述了如果调用eglCreatePbufferSurface时没有设置像素缓冲区的EGL_WIDTHEGL_HEIGHT参数,调用eglMakeCurrent会触发错误。这是创建像素缓冲区(full source located here)的最小java示例,确保输入的宽度和高度大于零:

private void eglSetup(int width, int height) {
    mEGL = (EGL10)EGLContext.getEGL();
    mEGLDisplay = mEGL.eglGetDisplay(EGL10.EGL_DEFAULT_DISPLAY);
    if (!mEGL.eglInitialize(mEGLDisplay, null)) {
        throw new RuntimeException("unable to initialize EGL10");
    }

    // Configure EGL for pbuffer and OpenGL ES 2.0.  We want enough RGB bits
    // to be able to tell if the frame is reasonable.
    int[] attribList = {
            EGL10.EGL_RED_SIZE, 8,
            EGL10.EGL_GREEN_SIZE, 8,
            EGL10.EGL_BLUE_SIZE, 8,
            EGL10.EGL_SURFACE_TYPE, EGL10.EGL_PBUFFER_BIT,
            EGL10.EGL_RENDERABLE_TYPE, EGL_OPENGL_ES2_BIT,
            EGL10.EGL_NONE
    };
    EGLConfig[] configs = new EGLConfig[1];
    int[] numConfigs = new int[1];
    if (!mEGL.eglChooseConfig(mEGLDisplay, attribList, configs, 1, numConfigs)) {
        throw new RuntimeException("unable to find RGB888+pbuffer EGL config");
    }

    // Configure context for OpenGL ES 2.0.
    int[] attrib_list = {
            EGL14.EGL_CONTEXT_CLIENT_VERSION, 2,
            EGL10.EGL_NONE
    };
    mEGLContext = mEGL.eglCreateContext(mEGLDisplay, configs[0], EGL10.EGL_NO_CONTEXT,
        attrib_list);
    checkEglError("eglCreateContext");
    if (mEGLContext == null) {
        throw new RuntimeException("null context");
    }

    // Create a pbuffer surface.  By using this for output, we can use glReadPixels
    // to test values in the output.
    int[] surfaceAttribs = {
            EGL10.EGL_WIDTH, width,
            EGL10.EGL_HEIGHT, height,
            EGL10.EGL_NONE
    };
    mEGLSurface = mEGL.eglCreatePbufferSurface(mEGLDisplay, configs[0], surfaceAttribs);
    checkEglError("eglCreatePbufferSurface");
    if (mEGLSurface == null) {
        throw new RuntimeException("surface was null");
    }

    mEGL.eglMakeCurrent(mEGLDisplay, mEGLSurface, mEGLSurface, mEGLContext);
}

如果不了解应用程序实施的更多细节,就很难确定确切的原因。这应该是识别和解决问题的良好起点。

【讨论】:

    【解决方案2】:

    此 EGL 错误通常是由特定于设备的硬件加速问题引起的。 Webviews 可能特别容易受到此错误的影响。尝试为有问题的视图禁用硬件加速。如果错误仍然存​​在,请确保您正确连接到 Activity 生命周期,因为这也可能导致 EGL 分配崩溃。具体来说,检查在封闭的 Activity 上调用时是否在 GLSurfaceView 上调用了 onPause 和 onResume。

    资源:

    1. CreateWindowSurface failed EGL_BAD_ALLOC
    2. GLSurfaceView EGL_BAD_ALLOC
    3. GLSurfaceView in Android 2.3.x consistently produces EGL_BAD_ALLOC

    【讨论】:

      猜你喜欢
      • 2012-09-08
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2016-10-08
      • 1970-01-01
      • 1970-01-01
      • 2017-06-30
      • 2014-10-20
      相关资源
      最近更新 更多