3

I have an Android app that renders an OpenGL scene. All of the OpenGL code is done in c++.

The problem I am having is that when I press the home button, and then return to the app, the OpenGL calls start to return errors.

Specifically, the ES 1.1 version fails on glDrawArrays with a logcat error <gl_draw_error_checks::550>: GL_INVALID_OPERATION

The ES 2.0 version fails on glUseProgram with a locat error of <core_glUseProgram:1496>: GL_INVALID_VALUE.

What is the proper process for leaving / returning to an OpenGL ES application?

Andon M. Coleman
  • 42,359
  • 2
  • 81
  • 106
default
  • 2,637
  • 21
  • 44

2 Answers2

3

So ultimately i fixed this issue by following some sample code in this book. In chapter 4, they have a sample that does all the egl calls in c++. So using that method i was able to create my own context and manage its lifetime rather than having the GLSurfaceView manage the lifetime.

Basically, I create a single context that is never destroyed. Then when the surface goes away, i simply call eglMakeCurrent( display, NULL, NULL, NULL ) and stop my render loop, and when the surface is restored I make the context current with the new surface. This works fine and I have no more crashes and don't have to reload my shaders or geometry everytime the app is backgrounded or screen is rotated.

default
  • 2,637
  • 21
  • 44
0

eglContext is likely to be destroyed when App paused.but there are a method provided by GLSurfaceView called setPreserveEGLContextOnPause.

you can also refer to the discuss.

Community
  • 1
  • 1
Gavin
  • 303
  • 3
  • 12