| Summary: | onResume() causes old window handles to get clobbered | ||
|---|---|---|---|
| Product: | SDL | Reporter: | Stevie Frederick <leflor> |
| Component: | video | Assignee: | Sam Lantinga <slouken> |
| Status: | RESOLVED FIXED | QA Contact: | Sam Lantinga <slouken> |
| Severity: | major | ||
| Priority: | P2 | CC: | enno.rehling, gabomdq |
| Version: | HG 2.0 | ||
| Hardware: | ARM | ||
| OS: | Android (All) | ||
| Attachments: |
A few fixes required for proper pause/resume support on Android
Recreate the GL context automatically Recreate the GL context automatically |
||
|
Description
Stevie Frederick
2012-02-19 09:58:05 UTC
Hi, I think what you mention here is what I talked about in this post: http://forums.libsdl.org/viewtopic.php?t=7926&highlight= In short, previously SDL under Android right out quit when it lost focus, now it remains active but as you loose the GL context, you have to re create your textures. This is an Android only issue, as it doesn't seem to happen in any of the other supported architectures (even iOS). I suggested in my post some potentials fixes/workarounds but I haven't got around to implementing any of these. Created attachment 862 [details]
A few fixes required for proper pause/resume support on Android
This is a patch for SDLActivity.java that allows for pause/resume of activities and it should work as is under Android > 3.0.
To complement this patch, on you app you should listen for SDL_WINDOWEVENT_RESTORED (only under Android), and call SDL_GL_CreateContext(window) to restore the GL Context, that's the only thing you need to do.
The only "to do" for this would be sending a message where the Log line:
Log.e("SDL", "Old EGL Context doesnt work, trying with a new one");
is, to let the app know that it has to reload its textures...or we could get fancy and try to do it automagically (saving all textures to memory on pause and then restoring them on resume?)
Created attachment 864 [details]
Recreate the GL context automatically
Attaching my best attempt at the complimentary part of the first patch, the one that automatically re-creates the GL context on the appropriate thread.
There's no simple solution to this problem...You can't add this in GLES_WindowEvent / GLES2_WindowEvent because they are called through SDL_SetEventFilter, so they are called in the Java thread vs the SDL thread.
In the interest of speed, I've added a global variable (yuck!) that tracks the hidden/paused state of the Android window, and we do the peeking of events only in the case that the window has been hidden.
There's two To-Dos in the patch:
* TODO: Should we double check if we are on the same thread that originally created the GL context? If for some reason the user is pumping events in a separate thread other than the main SDL thread, this can cause problems.
* TODO: If the context can't be recovered, send the user a message to let him know that the GL context has changed behind the scenes
Created attachment 880 [details]
Recreate the GL context automatically
Uploading improved patch, this one uses two semaphores and no messages, and offers the possibility of blocking the event loop while on pause with #if SDL_ANDROID_BLOCK_ON_PAUSE
I'm using this patch now in my system and it works like a charm.
|