From 4a9ce5dae1e90be21dea89e306b4c81d0ea42f4e Mon Sep 17 00:00:00 2001 From: Evan Debenham Date: Wed, 1 Nov 2017 02:14:46 -0400 Subject: [PATCH] v0.6.2a: added safety and sync checks for a number of rare crashes --- .../shatteredpixeldungeon/actors/hero/Hero.java | 2 +- .../effects/particles/WindParticle.java | 2 +- .../shatteredpixeldungeon/levels/PrisonLevel.java | 2 +- .../shatteredpixeldungeon/levels/SewerLevel.java | 2 +- .../shatteredpixeldungeon/scenes/CellSelector.java | 3 ++- .../shatteredpixeldungeon/sprites/ItemSprite.java | 4 ++-- .../shatteredpixeldungeon/ui/AttackIndicator.java | 8 ++++---- .../shatteredpixeldungeon/ui/BuffIndicator.java | 5 +++-- 8 files changed, 15 insertions(+), 13 deletions(-) diff --git a/core/src/main/java/com/shatteredpixel/shatteredpixeldungeon/actors/hero/Hero.java b/core/src/main/java/com/shatteredpixel/shatteredpixeldungeon/actors/hero/Hero.java index 9297fd243..b04b15e58 100644 --- a/core/src/main/java/com/shatteredpixel/shatteredpixeldungeon/actors/hero/Hero.java +++ b/core/src/main/java/com/shatteredpixel/shatteredpixeldungeon/actors/hero/Hero.java @@ -989,7 +989,7 @@ public class Hero extends Char { boolean newMob = false; Mob target = null; - for (Mob m : Dungeon.level.mobs) { + for (Mob m : Dungeon.level.mobs.toArray(new Mob[0])) { if (fieldOfView[ m.pos ] && m.alignment == Alignment.ENEMY) { visible.add(m); if (!visibleEnemies.contains( m )) { diff --git a/core/src/main/java/com/shatteredpixel/shatteredpixeldungeon/effects/particles/WindParticle.java b/core/src/main/java/com/shatteredpixel/shatteredpixeldungeon/effects/particles/WindParticle.java index 67b2146ff..4ed794f99 100644 --- a/core/src/main/java/com/shatteredpixel/shatteredpixeldungeon/effects/particles/WindParticle.java +++ b/core/src/main/java/com/shatteredpixel/shatteredpixeldungeon/effects/particles/WindParticle.java @@ -99,7 +99,7 @@ public class WindParticle extends PixelParticle { @Override public void update() { - if (visible = Dungeon.level.heroFOV[pos]) { + if (visible = (pos < Dungeon.level.heroFOV.length && Dungeon.level.heroFOV[pos])) { super.update(); diff --git a/core/src/main/java/com/shatteredpixel/shatteredpixeldungeon/levels/PrisonLevel.java b/core/src/main/java/com/shatteredpixel/shatteredpixeldungeon/levels/PrisonLevel.java index 9fbc6a32c..5e2936f7c 100644 --- a/core/src/main/java/com/shatteredpixel/shatteredpixeldungeon/levels/PrisonLevel.java +++ b/core/src/main/java/com/shatteredpixel/shatteredpixeldungeon/levels/PrisonLevel.java @@ -162,7 +162,7 @@ public class PrisonLevel extends RegularLevel { @Override public void update() { - if (visible = Dungeon.level.heroFOV[pos]) { + if (visible = (pos < Dungeon.level.heroFOV.length && Dungeon.level.heroFOV[pos])) { super.update(); } } diff --git a/core/src/main/java/com/shatteredpixel/shatteredpixeldungeon/levels/SewerLevel.java b/core/src/main/java/com/shatteredpixel/shatteredpixeldungeon/levels/SewerLevel.java index 9cb587ffb..89fa33d5b 100644 --- a/core/src/main/java/com/shatteredpixel/shatteredpixeldungeon/levels/SewerLevel.java +++ b/core/src/main/java/com/shatteredpixel/shatteredpixeldungeon/levels/SewerLevel.java @@ -180,7 +180,7 @@ public class SewerLevel extends RegularLevel { @Override public void update() { - if (visible = Dungeon.level.heroFOV[pos]) { + if (visible = (pos < Dungeon.level.heroFOV.length && Dungeon.level.heroFOV[pos])) { super.update(); diff --git a/core/src/main/java/com/shatteredpixel/shatteredpixeldungeon/scenes/CellSelector.java b/core/src/main/java/com/shatteredpixel/shatteredpixeldungeon/scenes/CellSelector.java index a8606e6ea..6ddbf5db7 100644 --- a/core/src/main/java/com/shatteredpixel/shatteredpixeldungeon/scenes/CellSelector.java +++ b/core/src/main/java/com/shatteredpixel/shatteredpixeldungeon/scenes/CellSelector.java @@ -25,6 +25,7 @@ import com.shatteredpixel.shatteredpixeldungeon.Dungeon; import com.shatteredpixel.shatteredpixeldungeon.ShatteredPixelDungeon; import com.shatteredpixel.shatteredpixeldungeon.actors.Actor; import com.shatteredpixel.shatteredpixeldungeon.actors.Char; +import com.shatteredpixel.shatteredpixeldungeon.actors.mobs.Mob; import com.shatteredpixel.shatteredpixeldungeon.items.Heap; import com.shatteredpixel.shatteredpixeldungeon.tiles.DungeonTilemap; import com.watabou.input.Touchscreen.Touch; @@ -57,7 +58,7 @@ public class CellSelector extends TouchArea { } else { PointF p = Camera.main.screenToCamera( (int)touch.current.x, (int)touch.current.y ); - for (Char mob : Dungeon.level.mobs){ + for (Char mob : Dungeon.level.mobs.toArray(new Mob[0])){ if (mob.sprite != null && mob.sprite.overlapsPoint( p.x, p.y)){ select( mob.pos ); return; diff --git a/core/src/main/java/com/shatteredpixel/shatteredpixeldungeon/sprites/ItemSprite.java b/core/src/main/java/com/shatteredpixel/shatteredpixeldungeon/sprites/ItemSprite.java index 92ad53535..0a24c76fb 100644 --- a/core/src/main/java/com/shatteredpixel/shatteredpixeldungeon/sprites/ItemSprite.java +++ b/core/src/main/java/com/shatteredpixel/shatteredpixeldungeon/sprites/ItemSprite.java @@ -208,7 +208,7 @@ public class ItemSprite extends MovieClip { } } - public void glow( Glowing glowing ){ + public synchronized void glow( Glowing glowing ){ this.glowing = glowing; if (glowing == null) resetColor(); } @@ -269,7 +269,7 @@ public class ItemSprite extends MovieClip { } @Override - public void update() { + public synchronized void update() { super.update(); visible = (heap == null || heap.seen); 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 82dbb5acd..78cb2ae44 100644 --- a/core/src/main/java/com/shatteredpixel/shatteredpixeldungeon/ui/AttackIndicator.java +++ b/core/src/main/java/com/shatteredpixel/shatteredpixeldungeon/ui/AttackIndicator.java @@ -63,7 +63,7 @@ public class AttackIndicator extends Tag { } @Override - protected void layout() { + protected synchronized void layout() { super.layout(); if (sprite != null) { @@ -127,7 +127,7 @@ public class AttackIndicator extends Tag { enable( bg.visible ); } - private void updateImage() { + private synchronized void updateImage() { if (sprite != null) { sprite.killAndErase(); @@ -151,14 +151,14 @@ public class AttackIndicator extends Tag { } private boolean enabled = true; - private void enable( boolean value ) { + private synchronized void enable( boolean value ) { enabled = value; if (sprite != null) { sprite.alpha( value ? ENABLED : DISABLED ); } } - private void visible( boolean value ) { + private synchronized void visible( boolean value ) { bg.visible = value; if (sprite != null) { sprite.visible = value; diff --git a/core/src/main/java/com/shatteredpixel/shatteredpixeldungeon/ui/BuffIndicator.java b/core/src/main/java/com/shatteredpixel/shatteredpixeldungeon/ui/BuffIndicator.java index 96fc398bc..3c718466b 100644 --- a/core/src/main/java/com/shatteredpixel/shatteredpixeldungeon/ui/BuffIndicator.java +++ b/core/src/main/java/com/shatteredpixel/shatteredpixeldungeon/ui/BuffIndicator.java @@ -39,8 +39,9 @@ import java.util.ArrayList; import java.util.LinkedHashMap; public class BuffIndicator extends Component { - - public static final int NONE = -1; + + //transparent icon + public static final int NONE = 63; //TODO consider creating an enum to store both index, and tint. Saves making separate images for color differences. public static final int MIND_VISION = 0;