Skip to content

Commit

Permalink
Merge pull request #5208 from IllianiCBT/stratCon_missingForceFailGra…
Browse files Browse the repository at this point in the history
…cefully

Handled Exception when Fetching Force by ID in `StratconPanel`
  • Loading branch information
HammerGS authored Nov 23, 2024
2 parents b3cfffc + c72bf65 commit 9c1fbc1
Showing 1 changed file with 12 additions and 1 deletion.
13 changes: 12 additions & 1 deletion MekHQ/src/mekhq/gui/StratconPanel.java
Original file line number Diff line number Diff line change
Expand Up @@ -655,6 +655,17 @@ private void drawForces(Graphics2D g2D) {

if (currentTrack.getAssignedCoordForces().containsKey(currentCoords)) {
for (int forceID : currentTrack.getAssignedCoordForces().get(currentCoords)) {
String forceName = "";
try {
Force force = campaign.getForce(forceID);
forceName = force.getName();
} catch (Exception e) {
// If we can't successfully fetch the Force, there is no point trying
// to draw it on the map.
logger.error(String.format("Failed to fetch force from ID %s", forceID));
continue;
}

g2D.setColor(Color.GREEN);

BufferedImage forceImage = getImage(StratconBiomeManifest.FORCE_FRIENDLY,
Expand All @@ -670,7 +681,7 @@ private void drawForces(Graphics2D g2D) {
TextAttribute.WEIGHT, TextAttribute.WEIGHT_BOLD));
g2D.setFont(newFont);

drawTextEffect(g2D, forceMarker, campaign.getForce(forceID).getName(), currentCoords);
drawTextEffect(g2D, forceMarker, forceName, currentCoords);

g2D.setFont(currentFont);
}
Expand Down

0 comments on commit 9c1fbc1

Please sign in to comment.