Up, this deserves some more visibility to developers :)

I agree with you, I took me a few hours of debug before I find my
black-screen-on-resume was caused by the RENDERMODE_WHEN_DIRTY and I
enventually came out fixing it like you did (except for the sleep).

On Nov 22, 8:24 am, "[email protected]"
<[email protected]> wrote:
> My OpenGL app animates only every now and then, so I decided to use
> RENDERMODE_WHEN_DIRTY to save some battery life. However, I found that
> when I go to Home Screen and return to my app, I often get a black
> screen, and I see this in logcat:
>
> E/SurfaceComposerClient( 6055): using an invalid surface id=1,
> identity=735 should be 738
>
> This seems to be caused by this code in GLSurfaceView (1.6 here, but
> 2.0 has same problem):
>
>                 synchronized (this) {
>                     ........
>                     if (mPaused) {
>                         mEglHelper.finish();
>                         needStart = true;
>                     }
>                     while (needToWait()) {
>                         wait();
>                     }
>                     .......
>                 }
>                 if (needStart) {
>                     mEglHelper.start();
>                     ......
>
> If I use RENDERMODE_WHEN_DIRTY, I will be stuck inside the wait()
> call. When my app is paused/resumed,  GLSurfaceView.{onPause,onResume}
> will be called, by the change in mPaused will be lost. So when wait()
> finally finishes, the mEglHelper.finish() and mEglHelper.start() lines
> are not executed, and I end up drawing into the wrong surface.
>
> The work around is simple but a bit ugly:
>
>     public MyView(....) {
>         super(....);
>         setRenderMode(GLSurfaceView.RENDERMODE_WHEN_DIRTY);
>     }
>
>     public void onResume() {
>         super.onResume();
>         setRenderMode(GLSurfaceView.RENDERMODE_WHEN_DIRTY);
>         requestRender();
>     }
>
>     public void onPause() {
>         setRenderMode(GLSurfaceView.RENDERMODE_CONTINUOUSLY);
>         android.os.SystemClock.sleep(60);
>         super.onPause();
>     }
>
> The trick is to temporarily get the GLSurfaceView to run in
> RENDERMODE_CONTINUOUSLY. I found the sleep(60) to be necessary to
> avoid race conditions that somehow left me hanging inside the wait()
> ---- but I am not sure if this is 100% scientific.
>
> Anyway, cheers, and save a few battery bars!
>
> P.S., I found this to be somewhat disconcerting ... as the longevity
> of this bug shows not too many people are trying to use OpenGL to make
> their UI faster -- and battery efficient. This probably means that
> iPhone apps will continue to look-and-feel better than Android for
> quite some time :-(

-- 
You received this message because you are subscribed to the Google
Groups "Android Developers" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
http://groups.google.com/group/android-developers?hl=en

Reply via email to