diff --git a/core/src/main/java/com/shatteredpixel/shatteredpixeldungeon/actors/Actor.java b/core/src/main/java/com/shatteredpixel/shatteredpixeldungeon/actors/Actor.java index 16c1345f9..0ea86159c 100644 --- a/core/src/main/java/com/shatteredpixel/shatteredpixeldungeon/actors/Actor.java +++ b/core/src/main/java/com/shatteredpixel/shatteredpixeldungeon/actors/Actor.java @@ -28,6 +28,7 @@ import com.shatteredpixel.shatteredpixeldungeon.Statistics; import com.shatteredpixel.shatteredpixeldungeon.actors.blobs.Blob; import com.shatteredpixel.shatteredpixeldungeon.actors.buffs.Buff; import com.shatteredpixel.shatteredpixeldungeon.actors.mobs.Mob; +import com.shatteredpixel.shatteredpixeldungeon.scenes.GameScene; import com.watabou.utils.Bundlable; import com.watabou.utils.Bundle; @@ -224,7 +225,11 @@ public abstract class Actor implements Bundlable { if (!doNext){ interrupted = false; + synchronized (Thread.currentThread()) { + synchronized (GameScene.class){ + GameScene.class.notify(); + } try { Thread.currentThread().wait(); } catch (InterruptedException e) { 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 9d28909d5..e5c910a79 100644 --- a/core/src/main/java/com/shatteredpixel/shatteredpixeldungeon/scenes/GameScene.java +++ b/core/src/main/java/com/shatteredpixel/shatteredpixeldungeon/scenes/GameScene.java @@ -414,17 +414,34 @@ public class GameScene extends PixelScene { public void destroy() { - freezeEmitters = false; - - scene = null; - Badges.saveGlobal(); - + //tell the actor thread to finish, then wait for it to complete any actions it may be doing. if (actorThread.isAlive()){ synchronized (actorThread) { actorThread.interrupt(); } + synchronized (GameScene.class){ + if (actorThread.getState() != Thread.State.WAITING) { + try { + GameScene.class.wait(5000); + } catch (InterruptedException e) { + ShatteredPixelDungeon.reportException(e); + } + synchronized (actorThread) { + if (actorThread.getState() != Thread.State.WAITING) { + Throwable t = new Throwable(); + t.setStackTrace(actorThread.getStackTrace()); + throw new RuntimeException("timeout waiting for actor thread! ", t); + } + } + } + } } + freezeEmitters = false; + + scene = null; + Badges.saveGlobal(); + super.destroy(); }