Skip to content

Commit

Permalink
Handled Exception when Fetching Force by ID in StratconPanel
Browse files Browse the repository at this point in the history
Added a try-catch block to handle errors when fetching a force by its ID in `StratconPanel.java`. This prevents the application from attempting to draw a force on the map if it fails to fetch the force data and logs an error message accordingly.
  • Loading branch information
IllianiCBT committed Nov 18, 2024
1 parent 3979544 commit c72bf65
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 c72bf65

Please sign in to comment.