From 778fafbcdd1c4e303db24a0c49060e4d4c8c1adc Mon Sep 17 00:00:00 2001 From: Evan Debenham Date: Tue, 26 Jan 2021 18:23:44 -0500 Subject: [PATCH] v0.9.2: added various safety checks to reduce the chance of crashes --- .../scenes/GameScene.java | 40 ++++++++++--------- .../ui/AttackIndicator.java | 16 ++++---- 2 files changed, 31 insertions(+), 25 deletions(-) diff --git a/core/src/main/java/com/shatteredpixel/shatteredpixeldungeon/scenes/GameScene.java b/core/src/main/java/com/shatteredpixel/shatteredpixeldungeon/scenes/GameScene.java index 728117db1..77e1529df 100644 --- a/core/src/main/java/com/shatteredpixel/shatteredpixeldungeon/scenes/GameScene.java +++ b/core/src/main/java/com/shatteredpixel/shatteredpixeldungeon/scenes/GameScene.java @@ -532,24 +532,10 @@ public class GameScene extends PixelScene { public void destroy() { //tell the actor thread to finish, then wait for it to complete any actions it may be doing. - if (actorThread != null && actorThread.isAlive()){ - synchronized (GameScene.class){ - synchronized (actorThread) { - actorThread.interrupt(); - } - try { - GameScene.class.wait(5000); - } catch (InterruptedException e) { - ShatteredPixelDungeon.reportException(e); - } - synchronized (actorThread) { - if (Actor.processing()) { - Throwable t = new Throwable(); - t.setStackTrace(actorThread.getStackTrace()); - throw new RuntimeException("timeout waiting for actor thread! ", t); - } - } - } + if (!waitForActorThread( 4500 )){ + Throwable t = new Throwable(); + t.setStackTrace(actorThread.getStackTrace()); + throw new RuntimeException("timeout waiting for actor thread! ", t); } Emitter.freezeEmitters = false; @@ -567,10 +553,28 @@ public class GameScene extends PixelScene { actorThread.interrupt(); } } + + public synchronized boolean waitForActorThread(int msToWait ){ + if (actorThread != null && actorThread.isAlive()){ + return true; + } + synchronized (actorThread) { + actorThread.interrupt(); + } + try { + GameScene.class.wait(msToWait); + } catch (InterruptedException e) { + ShatteredPixelDungeon.reportException(e); + } + synchronized (actorThread) { + return Actor.processing(); + } + } @Override public synchronized void onPause() { try { + waitForActorThread(500); Dungeon.saveAll(); Badges.saveGlobal(); Journal.saveGlobal(); diff --git a/core/src/main/java/com/shatteredpixel/shatteredpixeldungeon/ui/AttackIndicator.java b/core/src/main/java/com/shatteredpixel/shatteredpixeldungeon/ui/AttackIndicator.java index b0d300e1d..0fe83a9b6 100644 --- a/core/src/main/java/com/shatteredpixel/shatteredpixeldungeon/ui/AttackIndicator.java +++ b/core/src/main/java/com/shatteredpixel/shatteredpixeldungeon/ui/AttackIndicator.java @@ -50,13 +50,15 @@ public class AttackIndicator extends Tag { public AttackIndicator() { super( DangerIndicator.COLOR ); - - instance = this; - lastTarget = null; - - setSize( 24, 24 ); - visible( false ); - enable( false ); + + synchronized (this) { + instance = this; + lastTarget = null; + + setSize(24, 24); + visible(false); + enable(false); + } } @Override