Android -- GLSurfaceView EGL_BAD_ALLOC [英] Android -- GLSurfaceView EGL_BAD_ALLOC

查看:20
本文介绍了Android -- GLSurfaceView EGL_BAD_ALLOC的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的程序在两个 Activities 之间切换,每个活动都会扩展一个使用 VBO 的派生 GLSurfaceView.在两个Activity之间来回切换几次后,程序崩溃并抛出以下异常.每次有上下文切换时,VBO 缓冲区都会被删除,onStop() 会被调用,并且下一个 Activity 的 GLSurfaceView 的新实例会被膨胀.我将程序重构为仅在一个 GLSurfaceViewActivity 上运行,并且该程序似乎可以正常运行.只使用多边形和颜色,没有纹理.这是伤害:

<代码>Java.lang.RuntimeException:createContext 失败:EGL_BAD_ALLOC在 android.opengl.GLSurfaceView$EglHelper.throwEglException(GLSurfaceView.java:1079)在 android.opengl.GLSurfaceView$EglHelper.throwEglException(GLSurfaceView.java:1071)在 android.opengl.GLSurfaceView$EglHelper.start(GLSurfaceView.java:927)在 android.opengl.GLSurfaceView$GLThread.guardedRun(GLSurfaceView.java:1248)在 android.opengl.GLSurfaceView$GLThread.run(GLSurfaceView.java:1118)

通过一些互联网研究,这是一个:

公共类 ClearActivity 扩展 Activity {...剪断...@覆盖受保护的无效 onPause() {超级.onPause();mGLView.onPause();}@覆盖受保护的无效 onResume() {超级.onResume();mGLView.onResume();}私有 GLSurfaceView mGLView;}

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. 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. Here's the damage:


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)

From doing some internet research, this is a recognized bug. So how do I do damage control? +200 for a nudge in the right direction.

EDIT: I SOLVED THE PROBLEM (I FORGOT TO CALL ONPAUSE() / ONRESTART() ON THE VIEWS). FIRST PERSON TO PUT AN ANSWER ABOUT ANYTHING WHATSOEVER GETS +200.

解决方案

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:

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

这篇关于Android -- GLSurfaceView EGL_BAD_ALLOC的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆