From d0ac9a0d5cfef2eabf3e0d049c1f52b6b2d81479 Mon Sep 17 00:00:00 2001 From: sleet01 Date: Wed, 17 Jul 2024 23:23:44 -0700 Subject: [PATCH] Fix for Concurrent Modification exceptions in Precognition --- megamek/src/megamek/common/Board.java | 18 +++++++++++++++--- 1 file changed, 15 insertions(+), 3 deletions(-) diff --git a/megamek/src/megamek/common/Board.java b/megamek/src/megamek/common/Board.java index f163ad96db8..77918674bbb 100644 --- a/megamek/src/megamek/common/Board.java +++ b/megamek/src/megamek/common/Board.java @@ -1650,17 +1650,29 @@ public Hashtable> getSpecialHexDisplayTabl } public void setSpecialHexDisplayTable(Hashtable> shd) { + Hashtable> temp = new Hashtable<>(); for (Map.Entry> e: specialHexes.entrySet()) { for (SpecialHexDisplay special: e.getValue()) { if (special.getType() == SpecialHexDisplay.Type.ARTILLERY_MISS) { - if (!shd.containsKey(e.getKey())) { - shd.put(e.getKey(), new LinkedList<>()); + if (!temp.containsKey(e.getKey())) { + temp.put(e.getKey(), new LinkedList<>()); } - shd.get(e.getKey()).add(special); + temp.get(e.getKey()).add(special); } } } + // Swap new Hashtable in for old specialHexes = shd; + + // Add miss instances back + for (Map.Entry> e: temp.entrySet()) { + for(SpecialHexDisplay miss: e.getValue()) { + if (!specialHexes.containsKey(e.getKey())) { + specialHexes.put(e.getKey(), new LinkedList<>()); + } + specialHexes.get(e.getKey()).add(miss); + } + } } public void setType(int t) {