From 4a94f12c8b79310cc57754a2db0c4a68e0036286 Mon Sep 17 00:00:00 2001 From: Regalis Date: Mon, 29 May 2017 17:59:24 +0300 Subject: [PATCH] Item list is manually cleared if there are items left after unloading a sub. The "ItemList.Count == 0" assertion failed during one of the testing sessions. No idea why or how to reproduce it, but I hope this will do as a workaround until we figure out the actual cause. --- Subsurface/Source/Map/Submarine.cs | 20 ++++++++++++++++++-- 1 file changed, 18 insertions(+), 2 deletions(-) diff --git a/Subsurface/Source/Map/Submarine.cs b/Subsurface/Source/Map/Submarine.cs index ba24e6029..4e74bad2c 100644 --- a/Subsurface/Source/Map/Submarine.cs +++ b/Subsurface/Source/Map/Submarine.cs @@ -1277,9 +1277,25 @@ namespace Barotrauma if (GameMain.GameScreen.Cam != null) GameMain.GameScreen.Cam.TargetPos = Vector2.Zero; - Entity.RemoveAll(); + RemoveAll(); - System.Diagnostics.Debug.Assert(Item.ItemList.Count == 0); + if (Item.ItemList.Count > 0) + { + List items = new List(Item.ItemList); + foreach (Item item in items) + { + DebugConsole.ThrowError("Error while unloading submarines - item \""+item.Name+"\" not removed"); + try + { + item.Remove(); + } + catch (Exception e) + { + DebugConsole.ThrowError("Error while removing \"" + item.Name + "\"!", e); + } + } + Item.ItemList.Clear(); + } PhysicsBody.list.Clear();