Skip to content

Commit

Permalink
Issue 2302 fix
Browse files Browse the repository at this point in the history
  • Loading branch information
SJuliez committed Nov 18, 2020
1 parent 236fe2e commit dbb7d25
Showing 1 changed file with 7 additions and 0 deletions.
7 changes: 7 additions & 0 deletions megamek/src/megamek/common/MapSettings.java
Original file line number Diff line number Diff line change
Expand Up @@ -574,6 +574,11 @@ public void setMapSize(int mapWidth, int mapHeight) {
if ((mapWidth <= 0) || (mapHeight <= 0)) {
throw new IllegalArgumentException("Total map area must be positive");
}

// If the map has become smaller, shrink the list by removing surplus elements
if (mapWidth * mapHeight < boardsSelected.size()) {
boardsSelected.subList(mapWidth * mapHeight, boardsSelected.size()).clear();
}

this.mapWidth = mapWidth;
this.mapHeight = mapHeight;
Expand All @@ -584,6 +589,8 @@ public void setMapSize(int mapWidth, int mapHeight) {
boardsSelected.set(i, null);
}
}

// Fill the list with null elements if the map has grown
while (boardsSelected.size() < (mapWidth * mapHeight)) {
boardsSelected.add(null);
}
Expand Down

0 comments on commit dbb7d25

Please sign in to comment.