GLSurfaceView EGL_BAD_ALLOC

发布于 2024-11-08 17:42:41 字数 1108 浏览 0 评论 0原文

我的程序在两个 Activity 之间切换,每个 Activity 都会膨胀一个使用 VBO 的派生 GLSurfaceView

在两个 Activity 之间来回切换几次后,程序崩溃并抛出以下异常:

Java.lang.RuntimeException: createContext failed: EGL_BAD_ALLOC
   at android.opengl.GLSurfaceView$EglHelper
      .throwEglException(GLSurfaceView.java:1079)
   at android.opengl.GLSurfaceView$EglHelper
      .throwEglException(GLSurfaceView.java:1071)
   at android.opengl.GLSurfaceView$EglHelper
      .start(GLSurfaceView.java:927)
   at android.opengl.GLSurfaceView$GLThread
      .guardedRun(GLSurfaceView.java:1248)
   at android.opengl.GLSurfaceView$GLThread
      .run(GLSurfaceView.java:1118)

每次进行上下文切换时,VBO 缓冲区都会被删除,调用 onStop() 并调用下一个 Activity 的新实例 < code>GLSurfaceView 已膨胀。

我重构了程序,使其仅在一个 GLSurfaceViewActivity 上运行,并且该程序似乎运行顺利。

仅使用多边形和颜色,不使用纹理。

通过一些互联网研究,这是一个已识别的错误。那么如何进行损害控制呢?

编辑:我解决了问题(我忘记在视图上调用 ONPAUSE() / ONRESTART() )。

My program switches between two Activities that each inflate a derived GLSurfaceView that uses VBOs.

After switching back and forth between the two Activities a few times, the program crashes and throws the following exception:

Java.lang.RuntimeException: createContext failed: EGL_BAD_ALLOC
   at android.opengl.GLSurfaceView$EglHelper
      .throwEglException(GLSurfaceView.java:1079)
   at android.opengl.GLSurfaceView$EglHelper
      .throwEglException(GLSurfaceView.java:1071)
   at android.opengl.GLSurfaceView$EglHelper
      .start(GLSurfaceView.java:927)
   at android.opengl.GLSurfaceView$GLThread
      .guardedRun(GLSurfaceView.java:1248)
   at android.opengl.GLSurfaceView$GLThread
      .run(GLSurfaceView.java:1118)

Each time there is a context switch the VBO buffers are deleted, onStop() is called, and a new instance of the next Activity's GLSurfaceView is inflated.

I refactored the program to run on only one GLSurfaceView and Activity, and the program seems to run without incident.

Only polygons and colors are used, no textures.

From doing some internet research, this is a recognized bug. So how do I do damage control?

EDIT: I SOLVED THE PROBLEM (I FORGOT TO CALL ONPAUSE() / ONRESTART() ON THE VIEWS).

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

独守阴晴ぅ圆缺 2024-11-15 17:42:41

令人烦恼的是,我还不能发表评论,但我认为你的意思是 onResume,而不是 onRestart。您的 Activity 可以在不停止的情况下暂停,这会导致 onPause,但不会导致 onRestart。

此图片(来自 Activity 文档)很好地展示了此 Activity 生命周期:

http://developer.android.com/images/activity_lifecycle.png

总之,记得将 onPause 和 onResume 传递给都是你的超级并到 GLSurfaceView。

来自 http://android-developers.blogspot.com/2009/04/介绍-glsurfaceview.html

public class ClearActivity extends Activity {
    ... snip ...

    @Override
    protected void onPause() {
        super.onPause();
        mGLView.onPause();
    }

    @Override
    protected void onResume() {
        super.onResume();
        mGLView.onResume();
    }

    private GLSurfaceView mGLView;
}

Annoyingly I can't post a comment yet, but I think you mean onResume, not onRestart. Your Activity can be paused without being stopped, which would cause onPause, but not onRestart.

This image (from the Activity docs) shows this activity life cycle very nicely:

http://developer.android.com/images/activity_lifecycle.png

In short, remember to pass onPause and onResume to both your super and to the GLSurfaceView.

From http://android-developers.blogspot.com/2009/04/introducing-glsurfaceview.html:

public class ClearActivity extends Activity {
    ... snip ...

    @Override
    protected void onPause() {
        super.onPause();
        mGLView.onPause();
    }

    @Override
    protected void onResume() {
        super.onResume();
        mGLView.onResume();
    }

    private GLSurfaceView mGLView;
}
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文