From 3a6ae784f7a13a6812c2bb3a04f623ab67644a41 Mon Sep 17 00:00:00 2001 From: Evan Debenham Date: Wed, 1 Nov 2017 01:49:31 -0400 Subject: [PATCH] v0.6.2a: added safety checks to some usages of curItem --- .../items/scrolls/InventoryScroll.java | 7 +++++++ .../items/stones/InventoryStone.java | 7 +++++++ .../shatteredpixeldungeon/items/wands/Wand.java | 11 +++++++++-- 3 files changed, 23 insertions(+), 2 deletions(-) diff --git a/core/src/main/java/com/shatteredpixel/shatteredpixeldungeon/items/scrolls/InventoryScroll.java b/core/src/main/java/com/shatteredpixel/shatteredpixeldungeon/items/scrolls/InventoryScroll.java index f95547bed..9c744c078 100644 --- a/core/src/main/java/com/shatteredpixel/shatteredpixeldungeon/items/scrolls/InventoryScroll.java +++ b/core/src/main/java/com/shatteredpixel/shatteredpixeldungeon/items/scrolls/InventoryScroll.java @@ -73,6 +73,13 @@ public abstract class InventoryScroll extends Scroll { protected static WndBag.Listener itemSelector = new WndBag.Listener() { @Override public void onSelect( Item item ) { + + //FIXME this safety check shouldn't be necessary + //it would be better to eliminate the curItem static variable. + if (!(curItem instanceof InventoryScroll)){ + return; + } + if (item != null) { ((InventoryScroll)curItem).onItemSelected( item ); diff --git a/core/src/main/java/com/shatteredpixel/shatteredpixeldungeon/items/stones/InventoryStone.java b/core/src/main/java/com/shatteredpixel/shatteredpixeldungeon/items/stones/InventoryStone.java index 5a8d5b109..056404ae9 100644 --- a/core/src/main/java/com/shatteredpixel/shatteredpixeldungeon/items/stones/InventoryStone.java +++ b/core/src/main/java/com/shatteredpixel/shatteredpixeldungeon/items/stones/InventoryStone.java @@ -75,6 +75,13 @@ public abstract class InventoryStone extends Runestone { protected static WndBag.Listener itemSelector = new WndBag.Listener() { @Override public void onSelect( Item item ) { + + //FIXME this safety check shouldn't be necessary + //it would be better to eliminate the curItem static variable. + if (!(curItem instanceof InventoryStone)){ + return; + } + if (item != null) { ((InventoryStone)curItem).onItemSelected( item ); diff --git a/core/src/main/java/com/shatteredpixel/shatteredpixeldungeon/items/wands/Wand.java b/core/src/main/java/com/shatteredpixel/shatteredpixeldungeon/items/wands/Wand.java index 3ada5a011..e1c55ca40 100644 --- a/core/src/main/java/com/shatteredpixel/shatteredpixeldungeon/items/wands/Wand.java +++ b/core/src/main/java/com/shatteredpixel/shatteredpixeldungeon/items/wands/Wand.java @@ -347,8 +347,15 @@ public abstract class Wand extends Item { public void onSelect( Integer target ) { if (target != null) { - - final Wand curWand = (Wand)Wand.curItem; + + //FIXME this safety check shouldn't be necessary + //it would be better to eliminate the curItem static variable. + final Wand curWand; + if (curItem instanceof Wand) { + curWand = (Wand) Wand.curItem; + } else { + return; + } final Ballistica shot = new Ballistica( curUser.pos, target, curWand.collisionProperties); int cell = shot.collisionPos;