From: badlogicgames Date: Thu, 2 Dec 2010 02:06:29 +0000 (+0000) Subject: [fixed] busy wait in AndroidGraphics.pause()/destroy() magically transformed to somet... X-Git-Url: http://git.osdn.net/view?a=commitdiff_plain;h=8bd230521f401fb4253f03ef11aa5bc1102c846c;p=mikumikustudio%2Flibgdx-mikumikustudio.git [fixed] busy wait in AndroidGraphics.pause()/destroy() magically transformed to something sane! (thanks Nate). --- diff --git a/backends/gdx-backend-android/src/com/badlogic/gdx/backends/android/AndroidGraphics.java b/backends/gdx-backend-android/src/com/badlogic/gdx/backends/android/AndroidGraphics.java index cf5b070ae..fea20233a 100644 --- a/backends/gdx-backend-android/src/com/badlogic/gdx/backends/android/AndroidGraphics.java +++ b/backends/gdx-backend-android/src/com/badlogic/gdx/backends/android/AndroidGraphics.java @@ -322,16 +322,27 @@ public final class AndroidGraphics implements Graphics, Renderer { synchronized (synch) { running = false; pause = true; + while (pause) { + try { + synch.wait(); + } catch (InterruptedException ignored) { + } + } } - while (pause); // busy wait. ya, nasty... } void destroy() { synchronized (synch) { running = false; destroy = true; + + while (destroy) { + try { + synch.wait(); + } catch(InterruptedException ex) { + } + } } - while (destroy); } @Override @@ -340,42 +351,44 @@ public final class AndroidGraphics implements Graphics, Renderer { deltaTime = (time - lastFrameTime) / 1000000000.0f; lastFrameTime = time; mean.addValue(deltaTime); - + boolean lrunning = false; boolean lpause = false; boolean ldestroy = false; boolean lresume = false; - - synchronized(synch) { + + synchronized (synch) { lrunning = running; lpause = pause; ldestroy = destroy; lresume = resume; - - if (resume) { + + if (resume) { resume = false; } - - if (pause) { - pause = false; + + if (pause) { + pause = false; + synch.notifyAll(); } - - if (destroy) { + + if (destroy) { destroy = false; - } + synch.notifyAll(); + } } - + if (lresume) { app.listener.resume(); Gdx.app.log("AndroidGraphics", "resumed"); } - + if (lrunning) { - ((AndroidInput)Gdx.input).processEvents(); + app.input.processEvents(); app.listener.render(); } - if (lpause) { + if (lpause) { app.listener.pause(); Gdx.app.log("AndroidGraphics", "paused"); } @@ -383,8 +396,8 @@ public final class AndroidGraphics implements Graphics, Renderer { if (ldestroy) { app.listener.dispose(); Gdx.app.log("AndroidGraphics", "destroyed"); - } - + } + if (time - frameStart > 1000000000) { fps = frames; frames = 0;