Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Prevent pilot tooltip exceptions #6107

Merged
merged 1 commit into from
Oct 17, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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