1

I finally found why on some Samsung devices all of the textures are appearing white.

It appears that when the user opens the game, sometimes the textures are not loading and the user has to minimize and restore the game so the onResume() method gets called and load again the textures. My code is just a huge mess so I don't really what to find the root of the problem and fix it (the game is in retirement stage, not worth spending days), I'm thinking of a work around.

So my question is: how can I check if OpenGL has lost context? Is any variable changing its value? Can I check if a specific texture exists in the context?

I know it's losing it when the app goes to the background but in my case this is not the case.

0xCursor
  • 2,242
  • 4
  • 15
  • 33
SteveL
  • 3,331
  • 4
  • 32
  • 57

1 Answers1

2

I don't quite get how you are loading your textures. onResume() should be a good place to do so if you disposed them in onPause()... just to free some memory when the user leaves the activity. Anyway, I’ll stick to your question.

In a simple case, you should initialize your textures inside onSurfaceCreated(). Also, don't do things like this:

if (texture != null)
   texture = initializeTexture();

because that doesn't mean it's loaded into the OpenGL memory, that's just a reference to a Java object which many times lives longer than the OpenGL context (especially if it's static).

Some offical doc:

http://developer.android.com/reference/android/opengl/GLSurfaceView.Renderer.html

EGL Context Lost

There are situations where the EGL rendering context will be lost. This typically happens when device wakes up after going to sleep. When the EGL context is lost, all OpenGL resources (such as textures) that are associated with that context will be automatically deleted. In order to keep rendering correctly, a renderer must recreate any lost resources that it still needs. The onSurfaceCreated(GL10, EGLConfig) method is a convenient place to do this.

0xCursor
  • 2,242
  • 4
  • 15
  • 33
aacotroneo
  • 2,170
  • 16
  • 22