From 78b85540154b29469c557aed34a29dde53f5727e Mon Sep 17 00:00:00 2001 From: kuronekochomusuke Date: Wed, 25 Oct 2023 17:48:05 -0400 Subject: [PATCH] check getEntityFromAllSources, since this processes entites that in and out of the game. add null checks --- megamek/src/megamek/client/Client.java | 30 +++++++++++++++----------- 1 file changed, 18 insertions(+), 12 deletions(-) diff --git a/megamek/src/megamek/client/Client.java b/megamek/src/megamek/client/Client.java index 9807eefd11f..61c9691b756 100644 --- a/megamek/src/megamek/client/Client.java +++ b/megamek/src/megamek/client/Client.java @@ -1258,18 +1258,24 @@ public String receiveReport(Vector v) { } if (entityID != -1 && crewID != -1) { - Entity e = game.getEntity(entityID); - Crew crew = e.getCrew(); - // Adjust the portrait size to the GUI scale and number of pilots - float imgSize = UIUtil.scaleForGUI(PilotToolTip.PORTRAIT_BASESIZE); - imgSize /= 0.2f * (crew.getSlotCount() - 1) + 1; - Image portrait = crew.getPortrait(crewID).getBaseImage().getScaledInstance(-1, (int) imgSize, Image.SCALE_SMOOTH); - // convert image to base64, add to the tag and store in cache - BufferedImage bufferedImage = new BufferedImage(portrait.getWidth(null), portrait.getHeight(null), BufferedImage.TYPE_INT_RGB); - bufferedImage.getGraphics().drawImage(portrait, 0, 0, null); - String base64Text = ImageUtil.base64TextEncodeImage(bufferedImage); - String img = ""; - updatedReport = updatedReport.replace("", img); + Entity e = game.getEntityFromAllSources(entityID); + + if (e != null) { + Crew crew = e.getCrew(); + + if (crew != null) { + // Adjust the portrait size to the GUI scale and number of pilots + float imgSize = UIUtil.scaleForGUI(PilotToolTip.PORTRAIT_BASESIZE); + imgSize /= 0.2f * (crew.getSlotCount() - 1) + 1; + Image portrait = crew.getPortrait(crewID).getBaseImage().getScaledInstance(-1, (int) imgSize, Image.SCALE_SMOOTH); + // convert image to base64, add to the tag and store in cache + BufferedImage bufferedImage = new BufferedImage(portrait.getWidth(null), portrait.getHeight(null), BufferedImage.TYPE_INT_RGB); + bufferedImage.getGraphics().drawImage(portrait, 0, 0, null); + String base64Text = ImageUtil.base64TextEncodeImage(bufferedImage); + String img = ""; + updatedReport = updatedReport.replace("", img); + } + } } }