From 0a1b80a9dd0da5cd728999ef524e02d4fbfdf670 Mon Sep 17 00:00:00 2001 From: Sergii Pylypenko Date: Tue, 24 Jun 2014 19:09:57 +0300 Subject: [PATCH] Fixed SDL not sleeping while in background. It's actually a serious bug, but it wasn't that obvious, because all devices are multicore now. --- project/java/GLSurfaceView_SDL.java | 20 ++++++++++++++------ project/java/Video.java | 7 ++++++- 2 files changed, 20 insertions(+), 7 deletions(-) diff --git a/project/java/GLSurfaceView_SDL.java b/project/java/GLSurfaceView_SDL.java index 93c3a465e..8cc5c8371 100644 --- a/project/java/GLSurfaceView_SDL.java +++ b/project/java/GLSurfaceView_SDL.java @@ -1059,14 +1059,21 @@ public class GLSurfaceView_SDL extends SurfaceView implements SurfaceHolder.Call } while (needToWait()) { //Log.v("SDL", "GLSurfaceView_SDL::run(): paused"); - try { - wait(500); - } catch(Exception e) { } + synchronized(this) { + try + { + wait(500); + } + catch(InterruptedException e) + { + Log.v("SDL", "GLSurfaceView_SDL::GLThread::SwapBuffers(): Who dared to interrupt my slumber?"); + Thread.interrupted(); // Clear the flag + } + } } synchronized (this) { - if (mDone) { + if (mDone) return false; - } // changed = mSizeChanged; w = mWidth; h = mHeight; @@ -1198,6 +1205,7 @@ public class GLSurfaceView_SDL extends SurfaceView implements SurfaceHolder.Call public void requestExitAndWait() { // don't call this from GLThread thread or it is a guaranteed // deadlock! + Log.v("SDL", "GLSurfaceView_SDL::requestExitAndWait()"); synchronized(this) { mDone = true; notify(); @@ -1205,7 +1213,7 @@ public class GLSurfaceView_SDL extends SurfaceView implements SurfaceHolder.Call try { join(); } catch (InterruptedException ex) { - Thread.currentThread().interrupt(); + //Thread.currentThread().interrupt(); } } diff --git a/project/java/Video.java b/project/java/Video.java index 8885661a5..deba57b74 100644 --- a/project/java/Video.java +++ b/project/java/Video.java @@ -960,7 +960,12 @@ class DemoGLSurfaceView extends GLSurfaceView_SDL { try { mRenderer.wait(300L); // And sometimes the app decides not to render at all, so this timeout should not be big. - } catch (InterruptedException e) { } + } + catch (InterruptedException e) + { + Log.v("SDL", "DemoGLSurfaceView::limitEventRate(): Who dared to interrupt my slumber?"); + Thread.interrupted(); + } } } }