From e81f90fa68094dd963875de0732d9493c0d5c6c2 Mon Sep 17 00:00:00 2001 From: NickAragua Date: Tue, 2 Mar 2021 16:15:16 -0500 Subject: [PATCH] more robust orphan cleanup --- megamek/src/megamek/common/Game.java | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/megamek/src/megamek/common/Game.java b/megamek/src/megamek/common/Game.java index 47ef8ff82dc..f3bb17c3ae5 100644 --- a/megamek/src/megamek/common/Game.java +++ b/megamek/src/megamek/common/Game.java @@ -1392,6 +1392,10 @@ public boolean hasEntity(int entityId) { * (probably due to double-blind) ignore it. */ public synchronized void removeEntity(int id, int condition) { + // always attempt to remove the entity with this ID from the entities collection + // as it may have gotten stuck there. + entities.removeIf(ent -> (ent.getId() == id)); + Entity toRemove = getEntity(id); if (toRemove == null) { // This next statement has been cluttering up double-blind @@ -1402,7 +1406,6 @@ public synchronized void removeEntity(int id, int condition) { return; } - entities.remove(toRemove); entityIds.remove(Integer.valueOf(id)); removeEntityPositionLookup(toRemove);