11

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).

genpfault
  • 51,148
  • 11
  • 85
  • 139
farm ostrich
  • 5,881
  • 14
  • 55
  • 81
  • 1
    Why would you be content with 100 FPS, even if the device in question may not support it? No vsync *is* a waste of power, rendering frames that never make it to screen. It sounds like vsync is enabled, which is perfectly fine. – Chris Dennett May 18 '11 at 02:07
  • 1
    59 / 60 are both common :) How do you measure FPS out of interest? It's possible that it's actually 60 but due to your measurement technique it's slightly below and doesn't round up. – Chris Dennett May 18 '11 at 02:25
  • 1
    What's the reason for needing 80, precisely? – Chris Dennett May 18 '11 at 02:52
  • Sure :) I'll take a look. By the way, don't base any of your timings on the frame rate, use (lastTimeMS + period) < System.currentTimeMillis(), which will be true when the period has elapsed. Only problem there is when you get multiple periods elapsing in the same timespan :) – Chris Dennett May 18 '11 at 03:05
  • you should make Calendar ca = Calendar.getInstance(); as member of of you surface to get instance one time – Yuriy Vikulov May 18 '11 at 04:32

1 Answers1

18

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;
}
zennehoy
  • 6,405
  • 28
  • 55