From 593f5d1b8e56b117da16d64236f76dfa838825fb Mon Sep 17 00:00:00 2001 From: Simon Date: Sat, 27 Jul 2024 11:18:41 +0200 Subject: [PATCH 1/2] guard against nonexistent weapon --- .../client/ui/swing/boardview/FiringArcSpriteHandler.java | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/megamek/src/megamek/client/ui/swing/boardview/FiringArcSpriteHandler.java b/megamek/src/megamek/client/ui/swing/boardview/FiringArcSpriteHandler.java index 19e76935acc..eb178c63137 100644 --- a/megamek/src/megamek/client/ui/swing/boardview/FiringArcSpriteHandler.java +++ b/megamek/src/megamek/client/ui/swing/boardview/FiringArcSpriteHandler.java @@ -67,6 +67,11 @@ public FiringArcSpriteHandler(BoardView boardView, ClientGUI clientGUI) { public void update(Entity entity, WeaponMounted weapon, @Nullable MovePath movePath) { firingEntity = entity; int weaponId = entity.getEquipmentNum(weapon); + if (weaponId == -1) { + // entities are replaced all the time by server-sent changes, must always guard + clearValues(); + return; + } // findRanges must be called before any call to testUnderWater due to usage of // global-style variables for some reason findRanges(weapon); From c87f3f77240e18a1f28227d2ac476a73f9c21dcb Mon Sep 17 00:00:00 2001 From: Simon Date: Sat, 27 Jul 2024 11:49:08 +0200 Subject: [PATCH 2/2] FiringArcSpriteHandler: more guards --- .../client/ui/swing/boardview/FiringArcSpriteHandler.java | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/megamek/src/megamek/client/ui/swing/boardview/FiringArcSpriteHandler.java b/megamek/src/megamek/client/ui/swing/boardview/FiringArcSpriteHandler.java index eb178c63137..b3b46f3ab76 100644 --- a/megamek/src/megamek/client/ui/swing/boardview/FiringArcSpriteHandler.java +++ b/megamek/src/megamek/client/ui/swing/boardview/FiringArcSpriteHandler.java @@ -64,8 +64,12 @@ public FiringArcSpriteHandler(BoardView boardView, ClientGUI clientGUI) { * @param weapon the selected weapon * @param movePath planned movement in the movement phase */ - public void update(Entity entity, WeaponMounted weapon, @Nullable MovePath movePath) { + public void update(@Nullable Entity entity, @Nullable WeaponMounted weapon, @Nullable MovePath movePath) { firingEntity = entity; + if ((entity == null) || (weapon == null)) { + clearValues(); + return; + } int weaponId = entity.getEquipmentNum(weapon); if (weaponId == -1) { // entities are replaced all the time by server-sent changes, must always guard