From 516336b269f9a83aad8f0494abb9425d438565ed Mon Sep 17 00:00:00 2001 From: degr8pheonix Date: Thu, 17 Oct 2024 09:27:09 +1000 Subject: [PATCH] Added conditional null checks prior to removing a meter in Extortion and DanceParty upgrades. Prior to the fix was causing game crashes in main. --- .../game/components/upgrades/DancePartyUpgrade.java | 7 +++++-- .../game/components/upgrades/ExtortionUpgrade.java | 7 +++++-- 2 files changed, 10 insertions(+), 4 deletions(-) diff --git a/source/core/src/main/com/csse3200/game/components/upgrades/DancePartyUpgrade.java b/source/core/src/main/com/csse3200/game/components/upgrades/DancePartyUpgrade.java index 84421bb6..735d4e6d 100644 --- a/source/core/src/main/com/csse3200/game/components/upgrades/DancePartyUpgrade.java +++ b/source/core/src/main/com/csse3200/game/components/upgrades/DancePartyUpgrade.java @@ -162,8 +162,11 @@ public void activate() { public void deactivate() { isActive = false; layout.setVisible(false); - meter.remove(); - text.remove(); + // Ensure the text and meter are removed from the stage after time finish + if (meter != null && meter.hasParent()) { + meter.remove(); + text.remove(); + } ServiceLocator.getDocketService().getEvents().trigger("UnDancing"); } diff --git a/source/core/src/main/com/csse3200/game/components/upgrades/ExtortionUpgrade.java b/source/core/src/main/com/csse3200/game/components/upgrades/ExtortionUpgrade.java index bd3543ff..94906680 100644 --- a/source/core/src/main/com/csse3200/game/components/upgrades/ExtortionUpgrade.java +++ b/source/core/src/main/com/csse3200/game/components/upgrades/ExtortionUpgrade.java @@ -144,8 +144,11 @@ public void deactivate() { ServiceLocator.getRandomComboService().getEvents().trigger("extortion unactive"); - meter.remove(); - text.remove(); + // Ensure the text and meter are removed from the stage after time finish + if (meter != null && meter.hasParent()) { + meter.remove(); + text.remove(); + } } /**