Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Losing OpenGL Textures in Android after a resume

My game is working correctly except in the case where I press the HOME button then resume. What needs to be done to use the textures again? I have tried calling onPause and onResume on the GLSurfaceView (when the activity's onPause and onResume are called).

Any ideas what I could be doing wrong?

like image 649
Ash McConnell Avatar asked May 11 '11 14:05

Ash McConnell


2 Answers

If all else fails, reload the textures:

Pseudocode

for tex in textures:
    if glIsTexture(tex.opengl_name) == false:
        glGenTextures(1, &tex.opengl_name)

    glBindTexture(tex.texture_target);
    glTexImage(..., texture.image);
like image 114
datenwolf Avatar answered Nov 08 '22 00:11

datenwolf


Even if you fixed your problem, just to give a bit of explanation that might help others.

Android does not guaranty to keep the OpenGL context alive when the activity is paused.

You have to recreate every OpenGL-resources on resume (texture in you case, but also VBOs etc etc).

Since API 11, you can ask kindly Android to keep the context, but there is no guaranty it would.

like image 40
rockeye Avatar answered Nov 08 '22 00:11

rockeye