From 023f746df7be9d38838dea7c46db51ca19a354e1 Mon Sep 17 00:00:00 2001 From: Evan Debenham Date: Fri, 18 Sep 2020 01:35:33 -0400 Subject: [PATCH] v0.9.0: added safety checks to prevent a few rare crashes --- .../src/main/java/com/watabou/noosa/Camera.java | 2 +- .../src/main/java/com/watabou/noosa/MovieClip.java | 3 ++- .../shatteredpixeldungeon/actors/hero/Hero.java | 13 +++++++++---- 3 files changed, 12 insertions(+), 6 deletions(-) diff --git a/SPD-classes/src/main/java/com/watabou/noosa/Camera.java b/SPD-classes/src/main/java/com/watabou/noosa/Camera.java index 6e6fd284c..be1b89871 100644 --- a/SPD-classes/src/main/java/com/watabou/noosa/Camera.java +++ b/SPD-classes/src/main/java/com/watabou/noosa/Camera.java @@ -93,7 +93,7 @@ public class Camera extends Gizmo { int length = all.size(); for (int i=0; i < length; i++) { Camera c = all.get( i ); - if (c.exists && c.active) { + if (c != null && c.exists && c.active) { c.update(); } } diff --git a/SPD-classes/src/main/java/com/watabou/noosa/MovieClip.java b/SPD-classes/src/main/java/com/watabou/noosa/MovieClip.java index 8d40b5301..263c819fb 100644 --- a/SPD-classes/src/main/java/com/watabou/noosa/MovieClip.java +++ b/SPD-classes/src/main/java/com/watabou/noosa/MovieClip.java @@ -62,7 +62,8 @@ public class MovieClip extends Image { frameTimer += Game.elapsed; while (frameTimer > curAnim.delay) { frameTimer -= curAnim.delay; - if (curFrame == curAnim.frames.length - 1) { + if (curFrame >= curAnim.frames.length - 1) { + curFrame = curAnim.frames.length - 1; if (curAnim.looped) { curFrame = 0; } 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 a5f4237bb..c0b9b60f8 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 @@ -1318,15 +1318,20 @@ public class Hero extends Char { if (cell == -1) { return false; } + + if (fieldOfView == null || fieldOfView.length != Dungeon.level.length()){ + fieldOfView = new boolean[Dungeon.level.length()]; + Dungeon.level.updateFieldOfView( this, fieldOfView ); + } - Char ch; - Heap heap; + Char ch = Actor.findChar( cell ); + Heap heap = Dungeon.level.heaps.get( cell ); if (Dungeon.level.map[cell] == Terrain.ALCHEMY && cell != pos) { curAction = new HeroAction.Alchemy( cell ); - } else if (fieldOfView[cell] && (ch = Actor.findChar( cell )) instanceof Mob) { + } else if (fieldOfView[cell] && ch instanceof Mob) { if (ch.alignment != Alignment.ENEMY && ch.buff(Amok.class) == null) { curAction = new HeroAction.Interact( ch ); @@ -1334,7 +1339,7 @@ public class Hero extends Char { curAction = new HeroAction.Attack( ch ); } - } else if ((heap = Dungeon.level.heaps.get( cell )) != null + } else if (heap != null //moving to an item doesn't auto-pickup when enemies are near... && (visibleEnemies.size() == 0 || cell == pos || //...but only for standard heaps, chests and similar open as normal.