From f28223431329425189c47956dc94e2e4ffbe8926 Mon Sep 17 00:00:00 2001
From: jsalmon3 <>
Date: Sat, 11 Sep 2004 12:56:07 +0000
Subject: [PATCH] Fixed editor crash when deleting units

---
 src/unit/unit_cache.cpp | 11 ++++++++---
 1 file changed, 8 insertions(+), 3 deletions(-)

diff --git a/src/unit/unit_cache.cpp b/src/unit/unit_cache.cpp
index 139b1e196..6726836b8 100644
--- a/src/unit/unit_cache.cpp
+++ b/src/unit/unit_cache.cpp
@@ -46,6 +46,7 @@
 #include "unit.h"
 #include "unittype.h"
 #include "map.h"
+#include "editor.h"
 
 /**
 **  Insert new unit into cache.
@@ -101,9 +102,13 @@ void UnitCacheRemove(Unit* unit)
 			} else {
 				// item is head of the list.
 				mf = TheMap.Fields + (i + unit->Y) * TheMap.Width + j + unit->X;
-				Assert(mf->UnitCache == listitem);
-				mf->UnitCache = listitem->Next;
-				Assert(!mf->UnitCache || !mf->UnitCache->Prev);
+				// FIXME: this check shouldn't be necessary but the editor
+				// FIXME: removes a unit from the cache twice
+				Assert(EditorRunning || mf->UnitCache == listitem);
+				if (mf->UnitCache == listitem) {
+					mf->UnitCache = listitem->Next;
+					Assert(!mf->UnitCache || !mf->UnitCache->Prev);
+				}
 			}
 
 			listitem->Next = listitem->Prev = NULL;