i can't tell you if my code works for the droid (i dont own one) but
it help fixing issues on the N1.
anyway i still have issues, sometimes it looks like i have 2 opengl
surfaces swapping from each other after a resume.
i'm gonna implement your modifications and tell you the effect on the
N1
Thanks a lot for everything, my work would have never exists without
yours ! (and sorry for my poor english ;) )

On 6 avr, 22:58, Robert Green <[email protected]> wrote:
> That occasional lock-up started happening constantly to me.  I messed
> around with a few things and found that the Droid really doesn't like
> to have its Display and Context destroyed all the time.
>
> I modified the code so that it would reuse the display and context as
> much as possible.  I looked through my GLES book and it doesn't say
> explicitly that you should always destroy them when your surface
> changes so I have to assume that it must be ok.  Even if it's not -
> this works and it wasn't working before, so I'm using it.
>
> Here are the code modifications:
>
> In EglHelper:
>
>     public void start() {
>         Log.d("EglHelper" + instanceId, "start()");
>         if (mEgl == null) {
>             Log.d("EglHelper" + instanceId, "getting new EGL");
>             /*
>              * Get an EGL instance
>              */
>             mEgl = (EGL10) EGLContext.getEGL();
>         } else {
>             Log.d("EglHelper" + instanceId, "reusing EGL");
>         }
>
>         if (mEglDisplay == null) {
>             Log.d("EglHelper" + instanceId, "getting new display");
>             /*
>              * Get to the default display.
>              */
>             mEglDisplay =
> mEgl.eglGetDisplay(EGL10.EGL_DEFAULT_DISPLAY);
>         } else {
>             Log.d("EglHelper" + instanceId, "reusing display");
>         }
>
>         if (mEglConfig == null) {
>             Log.d("EglHelper" + instanceId, "getting new config");
>             /*
>              * We can now initialize EGL for that display
>              */
>             int[] version = new int[2];
>             mEgl.eglInitialize(mEglDisplay, version);
>             mEglConfig = mEGLConfigChooser.chooseConfig(mEgl,
> mEglDisplay);
>         } else {
>             Log.d("EglHelper" + instanceId, "reusing config");
>         }
>
>         if (mEglContext == null) {
>             Log.d("EglHelper" + instanceId, "creating new context");
>             /*
>              * Create an OpenGL ES context. This must be done only
> once, an OpenGL context is a somewhat heavy object.
>              */
>             mEglContext = mEGLContextFactory.createContext(mEgl,
> mEglDisplay, mEglConfig);
>             if (mEglContext == null || mEglContext ==
> EGL10.EGL_NO_CONTEXT) {
>                 throw new RuntimeException("createContext failed");
>             }
>         } else {
>             Log.d("EglHelper" + instanceId, "reusing context");
>         }
>
>         mEglSurface = null;
>     }
>
> In GLThread:
>
>         private void stopEglLocked() {
>             if (mHaveEgl) {
>                 mHaveEgl = false;
>                 mEglHelper.destroySurface();
>                 sGLThreadManager.releaseEglSurface(this);
>             }
>         }
>
> Basically, you don't want a finish() in there.
>
> But we do need to finish somewhere so,
>
> At the end of guardedRun():
>
>             } finally {
>                 /*
>                  * clean-up everything...
>                  */
>                 synchronized (sGLThreadManager) {
>                     // Log.d("GLThread" + getId(), "Finishing.");
>                     stopEglLocked();
>                     mEglHelper.finish();
>                 }
>             }
>         }
>
> Then Finally in GLWallpaperService:
>
>         @Override
>         public void onDestroy() {
>             super.onDestroy();
>             mGLThread.requestExitAndWait();
>         }
>
> Of course you can remove any logging you don't want.
>
> The idea here is that we get to reuse the display and context on
> orientation changes which seems to make the Droid happy.  I haven't
> had a single crash since I switched to that, and I've probably
> reoriented 100 times since then in testing.
>
> I'll update the post on my blog to contain all the current code.
>
> On Apr 6, 2:57 pm, Robert Green <[email protected]> wrote:
>
>
>
> > By the way - things seemed good but I'm still having the occasional
> > lock-up.  The last one caused the phone to lock up badly enough that I
> > had to pull the battery :(
>
> > On Apr 6, 2:18 pm, Robert Green <[email protected]> wrote:
>
> > > I'm in disbelief, but it works!  Why does that hack work?  Is it a
> > > previous call to eglCreateWindowSurface which returns a bad value and
> > > after that, cleaning up causes a bad state and the next call to create
> > > window surface freezes?  I don't quite understand but I guess I never
> > > checked the return value of that call (because it wasn't returning
> > > when I was having problems, but maybe it was too late then :)).
>
> > > I tested and tested and tested again and this held up against all the
> > > orientation changes I could possibly make.  Good work!  I'll update
> > > the code I posted.
>
> > > BTW - I'm still seeing the occasional:
> > > E/libEGL  ( 5769): eglChooseConfig:897 error 3005 (EGL_BAD_CONFIG)
> > > W/dalvikvm( 5769): threadid=13: thread exiting with uncaught exception
> > > (group=0x4001b180)
> > > E/AndroidRuntime( 5769): Uncaught handler: thread GLThread 7 exiting
> > > due to uncaught exception
> > > E/AndroidRuntime( 5769): java.lang.IllegalArgumentException
> > > E/AndroidRuntime( 5769):        at
> > > com.google.android.gles_jni.EGLImpl.eglGetConfigAttrib(Native Method)
> > > E/AndroidRuntime( 5769):        at android.opengl.EglHelper
> > > $ComponentSizeChooser.findConfigAttrib(EglHelper.java:1007)
> > > E/AndroidRuntime( 5769):        at android.opengl.EglHelper
> > > $ComponentSizeChooser.chooseConfig(EglHelper.java:987)
> > > E/AndroidRuntime( 5769):        at android.opengl.EglHelper
> > > $BaseConfigChooser.chooseConfig(EglHelper.java:951)
> > > E/AndroidRuntime( 5769):        at
> > > android.opengl.EglHelper.start(EglHelper.java:127)
> > > E/AndroidRuntime( 5769):        at android.opengl.EglHelper
> > > $GLThread.guardedRun(EglHelper.java:421)
> > > E/AndroidRuntime( 5769):        at android.opengl.EglHelper
> > > $GLThread.run(EglHelper.java:358)
>
> > > I'm trying to track that one down but it's very hard to recreate.  It
> > > likes to happen the first time you run a newly installed gl live
> > > wallpaper but then it doesn't happen again for a while.
>
> > > Thanks guys for all your help!
>
> > > On Apr 6, 11:29 am, shaun <[email protected]> wrote:
>
> > > > Assuming I correctly identified the code that unixseb uses as the
> > > > workaround/fix for orientation changes on Droid in Live Wallpaper with
> > > > OpenGL, the following code is the same with the exception of
> > > > recursion:
>
> > > >     public EGLSurface createWindowSurface(EGL10 egl, EGLDisplay
> > > > display, EGLConfig config, Object nativeWindow) {
> > > >         EGLSurface eglSurface = null;
> > > >         while (eglSurface == null) {
> > > >             try {
> > > >                 eglSurface = egl.eglCreateWindowSurface(display,
> > > > config, nativeWindow, null);
> > > >             } catch (Throwable t) {
> > > >             } finally {
> > > >                 if (eglSurface == null) {
> > > >                     try {
> > > >                         Thread.sleep(10);
> > > >                     } catch (InterruptedException t) {
> > > >                     }
> > > >                 }
> > > >             }
>
> > > >         }
> > > >         return eglSurface;
> > > >     }
>
> > > > I'd like to know if unixseb's fix works for others.  I still cannot
> > > > test.
>
> > > > On Apr 6, 11:00 am, Ralf Schneider <[email protected]> wrote:
>
> > > > > I'm also interested in this topic. I got an 404 on the link: This 
> > > > > seems to
> > > > > work:
>
> > > > >http://code.google.com/p/earth-live-wallpaper/
>
> > > > > Thank you for sharing your code!
>
> > > > > 2010/4/6 unixseb <[email protected]>
>
> > > > > > have a look at the svn repository on code.google.com/project/earth-
> > > > > > live-wallpaper 
> > > > > > <http://code.google.com/project/earth-%0Alive-wallpaper>
> > > > > > the hack int the glwallpaperservice class avoid some crashes with
> > > > > > screen rotation on droids.
>
> > > > > > On 5 avr, 20:24, Robert Green <[email protected]> wrote:
> > > > > > > Oh, so you solved it??  What's the issue and what's the 
> > > > > > > workaround?
>
> > > > > > > On Apr 4, 3:33 pm, unixseb <[email protected]> wrote:
>
> > > > > > > > i can help you,
> > > > > > > > i'm having this issue with earth live wallpaper.
> > > > > > > > i tracked a bug in the swap function taht causes service dies, 
> > > > > > > > but i
> > > > > > > > was looking for this one for a long time now !
>
> > > > > > > > On 3 avr, 23:56, Robert Green <[email protected]> wrote:
>
> > > > > > > > > I've had this reported to me by a few people using the
> > > > > > > > >GLWallpaperServicecode I posted.  I've been debugging this for 
> > > > > > > > >hours
> > > > > > > > > and have so far tracked the problem down to
> > > > > > > > > egl.eglCreateWindowSurface(display, config, nativeWindow, 
> > > > > > > > > null);
>
> > > > > > > > > It never returns and every notifyAll() after that results in:
> > > > > > > > > W/SharedBufferStack( 1030): 
> > > > > > > > > waitForCondition(ReallocateCondition)
> > > > > > > > > timed out (identity=288, status=0). CPU may be pegged. trying 
> > > > > > > > > again.
>
> > > > > > > > > It seems to happen when switching orientation - so when the 
> > > > > > > > > surface
> > > > > > is
> > > > > > > > > being destroyed/recreated and more specifically when calls to 
> > > > > > > > > render
> > > > > > > > > the frame are being made at the same time.  If there are no 
> > > > > > > > > render
> > > > > > > > > calls happening while switching, things seem mostly ok.  I'm
> > > > > > debugging
> > > > > > > > > this further but I feel like a method like that should never
> > > > > > > > > deadlock.  Seems like a bug somewhere below the line to me.
>
> > > > > > > > > Since none of the GL init code from the shipped live 
> > > > > > > > > wallpapers was
> > > > > > > > > posted anywhere, I have no good reference to use for how to 
> > > > > > > > > properly
> > > > > > > > > handle the window resizing.  Clearly the code I'm using does 
> > > > > > > > > it a
> > > > > > > > > little differently but I still feel like a deadlock like this 
> > > > > > > > > should
> > > > > > > > > not occur.
>
> > > > > > --
> > > > > > 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]
>
> ...
>
> plus de détails »

-- 
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

To unsubscribe, reply using "remove me" as the subject.

Reply via email to