From d038e37f824810a1d28187981b204f47a76f9033 Mon Sep 17 00:00:00 2001 From: sleet01 Date: Sun, 28 Jul 2024 03:24:37 -0700 Subject: [PATCH] Add safety checks to each dialog call in the load-button handling --- .../client/ui/swing/DeploymentDisplay.java | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/megamek/src/megamek/client/ui/swing/DeploymentDisplay.java b/megamek/src/megamek/client/ui/swing/DeploymentDisplay.java index 40955580048..920b167adcb 100644 --- a/megamek/src/megamek/client/ui/swing/DeploymentDisplay.java +++ b/megamek/src/megamek/client/ui/swing/DeploymentDisplay.java @@ -720,6 +720,12 @@ public void actionPerformed(ActionEvent evt) { Messages.getString("DeploymentDisplay.loadUnitDialog.message", ce().getShortName(), ce().getUnusedString()), choices); + // Abort here if no Entity was generated + if (other == null) { + return; + } + + // Otherwise continue if (!(other instanceof Infantry)) { List bayChoices = new ArrayList<>(); for (Transporter t : ce().getTransports()) { @@ -738,6 +744,12 @@ public void actionPerformed(ActionEvent evt) { String msg = Messages.getString("DeploymentDisplay.loadUnitBayNumberDialog.message", ce().getShortName()); String bayString = (String) JOptionPane.showInputDialog(clientgui.getFrame(), msg, title, JOptionPane.QUESTION_MESSAGE, null, retVal, null); + + // No choice made? Bug out. + if (bayString == null) { + return; + } + int bayNum = Integer.parseInt(bayString.substring(0, bayString.indexOf(" "))); other.setTargetBay(bayNum); // We need to update the entity here so that the server knows about our target bay @@ -761,6 +773,12 @@ public void actionPerformed(ActionEvent evt) { Messages.getString("MovementDisplay.loadProtoClampMountDialog.message", ce().getShortName()), Messages.getString("MovementDisplay.loadProtoClampMountDialog.title"), JOptionPane.QUESTION_MESSAGE, null, retVal, null); + + // No choice made? Bug out. + if (bayString == null) { + return; + } + other.setTargetBay(bayString.equals(Messages.getString("MovementDisplay.loadProtoClampMountDialog.front")) ? 0 : 1); // We need to update the entity here so that the server knows about our target bay clientgui.getClient().sendUpdateEntity(other);