The SDL forums have moved to discourse.libsdl.org.
This is just a read-only archive of the previous forums, to keep old links working.


SDL Forum Index
SDL
Simple Directmedia Layer Forums
SDL 2.0 / Android pause/resume problems [solved]
pmacfarlane


Joined: 28 Jul 2012
Posts: 21
Location: Scotland
I am aware that on Android, when your app gets paused (e.g. by the user hitting the home key), the app's OpenGL context gets lost.

I've seen vague statements that your app must recreate its textures etc. However, can anybody shed any light on what _exactly_ is lost on a pause, and what needs to be done on resume?

My game (written in C, using OpenGL ES 2.0), has some textures and shaders. After a resume, glIsTexture(tex), glIsShader(shader), glIsProgram(program) all return TRUE for my textures and shaders.

For my textures, I recreate them by calling glTexImage2D() using pixel data kept from when the texture was originally loaded.

For my shaders, I rebuild and relink them.

Is there anything else that I need to do to recreate my OpenGL context?

As things are, after a resume, my app just displays a black screen. It is still running, as it logs various things when I touch the screen, but nothing is displayed.

Any help would be greatly appreciated! Or if anybody has (or can point to) example code that implements resume properly.

Thanks,
Philip.
SDL 2.0 / Android pause/resume problems (black screen)
gabomdq


Joined: 28 Jul 2011
Posts: 495
Location: Argentina
2012/8/9 pmacfarlane
Quote:
I am aware that on Android, when your app gets paused (e.g. by the user hitting the home key), the app's OpenGL context gets lost.





This should no longer be the case on the current version of SDL2, what device / Android version is giving you that problem?





--
Gabriel.
Re: SDL 2.0 / Android pause/resume problems [fixed!]
pmacfarlane


Joined: 28 Jul 2012
Posts: 21
Location: Scotland
gabomdq wrote:

This should no longer be the case on the current version of SDL2, what device / Android version is giving you that problem?


Gabriel,

Thanks for your reply. In light of what you said, I re-examined my code, and discovered that I'd not merged this part of changeset 0fa55ca2efdd

Code:

@@ -426,7 +429,6 @@
     public void surfaceCreated(SurfaceHolder holder) {
         Log.v("SDL", "surfaceCreated()");
         holder.setType(SurfaceHolder.SURFACE_TYPE_GPU);
-        SDLActivity.createEGLSurface();
         enableSensor(Sensor.TYPE_ACCELEROMETER, true);
     }


into my copy of SDLActivity.java. With this in place, it works perfectly.

Thanks a million!

Kind regards,
Philip.