Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
814 views
in Technique[技术] by (71.8m points)

opengl es - Android -- GLSurfaceView EGL_BAD_ALLOC

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.

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

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

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...