From 70cce2c8b3ecde2719fa5b29f1da03b330f2b8e9 Mon Sep 17 00:00:00 2001 From: Evan Debenham Date: Wed, 23 Aug 2017 03:43:10 -0400 Subject: [PATCH] v0.6.1b: fixed rare crashes caused by floating text --- .../effects/FloatingText.java | 52 ++++++++++--------- 1 file changed, 28 insertions(+), 24 deletions(-) diff --git a/core/src/main/java/com/shatteredpixel/shatteredpixeldungeon/effects/FloatingText.java b/core/src/main/java/com/shatteredpixel/shatteredpixeldungeon/effects/FloatingText.java index 8adf2ac93..9a8835c02 100644 --- a/core/src/main/java/com/shatteredpixel/shatteredpixeldungeon/effects/FloatingText.java +++ b/core/src/main/java/com/shatteredpixel/shatteredpixeldungeon/effects/FloatingText.java @@ -42,7 +42,7 @@ public class FloatingText extends RenderedText { private float cameraZoom = -1; - private static SparseArray> stacks = new SparseArray>(); + private static final SparseArray> stacks = new SparseArray>(); public FloatingText() { speed.y = - DISTANCE / LIFESPAN; @@ -65,7 +65,9 @@ public class FloatingText extends RenderedText { @Override public void kill() { if (key != -1) { - stacks.get( key ).remove( this ); + synchronized (stacks) { + stacks.get(key).remove(this); + } key = -1; } super.kill(); @@ -116,30 +118,32 @@ public class FloatingText extends RenderedText { private static void push( FloatingText txt, int key ) { - txt.key = key; - - ArrayList stack = stacks.get( key ); - if (stack == null) { - stack = new ArrayList(); - stacks.put( key, stack ); - } - - if (stack.size() > 0) { - FloatingText below = txt; - int aboveIndex = stack.size() - 1; - while (aboveIndex >= 0) { - FloatingText above = stack.get( aboveIndex ); - if (above.y + above.height() > below.y) { - above.y = below.y - above.height(); - - below = above; - aboveIndex--; - } else { - break; + synchronized (stacks) { + txt.key = key; + + ArrayList stack = stacks.get(key); + if (stack == null) { + stack = new ArrayList(); + stacks.put(key, stack); + } + + if (stack.size() > 0) { + FloatingText below = txt; + int aboveIndex = stack.size() - 1; + while (aboveIndex >= 0) { + FloatingText above = stack.get(aboveIndex); + if (above.y + above.height() > below.y) { + above.y = below.y - above.height(); + + below = above; + aboveIndex--; + } else { + break; + } } } + + stack.add(txt); } - - stack.add( txt ); } }