Skip to content

Commit

Permalink
Merge pull request #6107 from SJuliez/tooltip-portrait-exc
Browse files Browse the repository at this point in the history
Prevent pilot tooltip exceptions
  • Loading branch information
HammerGS authored Oct 17, 2024
2 parents 42fe286 + 1f08323 commit 68f41be
Showing 1 changed file with 14 additions and 10 deletions.
24 changes: 14 additions & 10 deletions megamek/src/megamek/client/ui/swing/tooltip/PilotToolTip.java
Original file line number Diff line number Diff line change
Expand Up @@ -218,19 +218,23 @@ private static StringBuilder crewPortraits(final Entity entity, boolean showDefa
String img = "";

if (!report) {
// Write the scaled portrait to file
// This is done to avoid using HTML rescaling on the portrait which does
// not do any smoothing and has extremely ugly results
String tempPath = Configuration.imagesDir() + TEMP_DIR + PORTRAIT_PREFIX
try {
// Write the scaled portrait to file
// This is done to avoid using HTML rescaling on the portrait which does
// not do any smoothing and has extremely ugly results
String tempPath = Configuration.imagesDir() + TEMP_DIR + PORTRAIT_PREFIX
+ crew.getExternalIdAsString() + "_" + i + PNG_EXT;
File tempFile = new File(tempPath);
if (!tempFile.exists()) {
BufferedImage bufferedImage = new BufferedImage(portrait.getWidth(null),
File tempFile = new File(tempPath);
if (!tempFile.exists()) {
BufferedImage bufferedImage = new BufferedImage(portrait.getWidth(null),
portrait.getHeight(null), BufferedImage.TYPE_INT_RGB);
bufferedImage.getGraphics().drawImage(portrait, 0, 0, null);
ImageIO.write(bufferedImage, "PNG", tempFile);
bufferedImage.getGraphics().drawImage(portrait, 0, 0, null);
ImageIO.write(bufferedImage, "PNG", tempFile);
}
img = "<IMG SRC=file:" + tempPath + ">";
} catch (Exception e) {
// when an error occurs, do not display any image
}
img = "<IMG SRC=file:" + tempPath + ">";
} else {
// span crew tag replaced later in Client.receiveReport with crew portrait
img = UIUtil.tag("span", "crew='" + entity.getId() + ":" + i + "'", "");
Expand Down

0 comments on commit 68f41be

Please sign in to comment.