[Android] Display garbage after "minimizing"

In android, when I “minimize” my app with the home button, and then return to it, the display is corrupted. It looks like the display is mixed with the OS display in a very glitchy way.

Any ideas?

I believe Android likes to trash the OpenGL context of apps that are not active.On Mar 20, 2014, at 4:01 AM, tjcbs wrote:

In android, when I “minimize” my app with the home button, and then return to it, the display is corrupted. It looks like the display is mixed with the OS display in a very glitchy way.

Any ideas?


SDL mailing list
SDL at lists.libsdl.org
http://lists.libsdl.org/listinfo.cgi/sdl-libsdl.org

Alex Szpakowski wrote:

I believe Android likes to trash the OpenGL context of apps that are not active.

I don’t think that is it, I am still rendering normally, the display is just overlaid with corruption.

With past revisions of SDL2 from Mercurial, I had to reinitialise SDL after returning to the foreground. Perhaps you need to do the same? Now, though,
it seems that I do not need to anymore. Then again, I am only using the Renderer API and not explicitly using OpenGL.

As a side note, I remember reading either on this mailing list or in the SDL2 wiki (I cannot remember which) that SDL_RendererPresent() should not be
called when the app is the background (Home button, switching to another app - gallery for instance). Perhaps that is related to your issue as well?
What I have done was when a SDL_APP_WILLENTERBACKGROUND event is received, I set a flag. The main-loop skips calling SDL_RendererPresent() if that
flag is set. This way the app can continue polling for events (e.g. waiting for the SDL_APP_DIDENTERFOREGROUND). Note that the SDL2 wiki states that
these events should be handled by an event filter as stated here http://wiki.libsdl.org/SDL_EventType#Android_and_iOS_Events.

Hope this helps.

Cheers,

AlvinOn 20/03/14 04:37, tjcbs wrote:

Alex Szpakowski wrote:
I believe Android likes to trash the OpenGL context of apps that are not active.

I don’t think that is it, I am still rendering normally, the display is just overlaid with corruption.

With past revisions of SDL2 from Mercurial, I had to reinitialise SDL after returning to the foreground. Perhaps you need to do the same? Now, though,
it seems that I do not need to anymore. Then again, I am only using the Renderer API and not explicitly using OpenGL.

As a side note, I remember reading either on this mailing list or in the SDL2 wiki (I cannot remember which) that SDL_RendererPresent() should not be
called when the app is the background (Home button, switching to another app - gallery for instance). Perhaps that is related to your issue as well?
What I have done was when a SDL_APP_WILLENTERBACKGROUND event is received, I set a flag. The main-loop skips calling SDL_RendererPresent() if that
flag is set. This way the app can continue polling for events (e.g. waiting for the SDL_APP_DIDENTERFOREGROUND). Note that the SDL2 wiki states that
these events should be handled by an event filter as stated here http://wiki.libsdl.org/SDL_EventType#Android_and_iOS_Events.

Hope this helps.

Cheers,

Alvin

I tried handling the background msgs, and unfortunately this did not fix the problem.

How long ago did you stop needing to reinitialize SDL? Did you have to re-create and re-upload all graphics assets? (I am using opengl directly, I assume the renderer api is similar?)

I’m not sure when. Since you are using opengl directly, what you could do is take a look at the internal android code in SDL2 and see what it does
when it emits the SDL_APP_DIDENTERFOREGROUND event. Perhaps you can duplicate that process? Perhaps there is does some opengl dance just before it
emits the event?

AlvinOn 21/03/14 04:35, tjcbs wrote:

Quote:

With past revisions of SDL2 from Mercurial, I had to reinitialise SDL after returning to the foreground. Perhaps you need to do the same? Now, though,
it seems that I do not need to anymore. Then again, I am only using the Renderer API and not explicitly using OpenGL.

As a side note, I remember reading either on this mailing list or in the SDL2 wiki (I cannot remember which) that SDL_RendererPresent() should not be
called when the app is the background (Home button, switching to another app - gallery for instance). Perhaps that is related to your issue as well?
What I have done was when a SDL_APP_WILLENTERBACKGROUND event is received, I set a flag. The main-loop skips calling SDL_RendererPresent() if that
flag is set. This way the app can continue polling for events (e.g. waiting for the SDL_APP_DIDENTERFOREGROUND). Note that the SDL2 wiki states that
these events should be handled by an event filter as stated here http://wiki.libsdl.org/SDL_EventType#Android_and_iOS_Events.

Hope this helps.

Cheers,

Alvin

I tried handling the background msgs, and unfortunately this did not fix the problem.

How long ago did you stop needing to reinitialize SDL? Did you have to re-create and re-upload all graphics assets? (I am using opengl directly, I
assume the renderer api is similar?)