diff --git a/Barotrauma/BarotraumaShared/Source/Characters/Animation/Ragdoll.cs b/Barotrauma/BarotraumaShared/Source/Characters/Animation/Ragdoll.cs index ea802d3d3..c9a371e76 100644 --- a/Barotrauma/BarotraumaShared/Source/Characters/Animation/Ragdoll.cs +++ b/Barotrauma/BarotraumaShared/Source/Characters/Animation/Ragdoll.cs @@ -24,7 +24,7 @@ namespace Barotrauma { if (limbs == null) { - DebugConsole.ThrowError("Attempted to access a potentially removed ragdoll. Character: " + character.Name + ", id: " + character.ID + ", removed: " + character.Removed); + DebugConsole.ThrowError("Attempted to access a potentially removed ragdoll. Character: " + character.Name + ", id: " + character.ID + ", removed: " + character.Removed + ", ragdoll removed: " + !list.Contains(this)); return new Limb[0]; } return limbs; diff --git a/Barotrauma/BarotraumaShared/Source/Map/Entity.cs b/Barotrauma/BarotraumaShared/Source/Map/Entity.cs index 1e2e48ae2..f2d49d803 100644 --- a/Barotrauma/BarotraumaShared/Source/Map/Entity.cs +++ b/Barotrauma/BarotraumaShared/Source/Map/Entity.cs @@ -133,6 +133,51 @@ namespace Barotrauma DebugConsole.ThrowError(" - " + e.ToString() + "(ID " + e.id + ")"); } } + if (Item.ItemList.Count > 0) + { + DebugConsole.ThrowError("Some items were not removed in Entity.RemoveAll:"); + foreach (Item item in Item.ItemList) + { + DebugConsole.ThrowError(" - " + item.Name + "(ID " + item.id + ")"); + } + + var items = new List(Item.ItemList); + foreach (Item item in items) + { + try + { + item.Remove(); + } + catch (Exception exception) + { + DebugConsole.ThrowError("Error while removing entity \"" + item.ToString() + "\"", exception); + } + } + Item.ItemList.Clear(); + } + if (Character.CharacterList.Count > 0) + { + DebugConsole.ThrowError("Some characters were not removed in Entity.RemoveAll:"); + foreach (Character character in Character.CharacterList) + { + DebugConsole.ThrowError(" - " + character.Name + "(ID " + character.id + ")"); + } + + var characters = new List(Character.CharacterList); + foreach (Character character in characters) + { + try + { + character.Remove(); + } + catch (Exception exception) + { + DebugConsole.ThrowError("Error while removing entity \"" + character.ToString() + "\"", exception); + } + } + Character.CharacterList.Clear(); + } + dictionary.Clear(); } diff --git a/Barotrauma/BarotraumaShared/Source/Map/Submarine.cs b/Barotrauma/BarotraumaShared/Source/Map/Submarine.cs index 24636e089..63277d538 100644 --- a/Barotrauma/BarotraumaShared/Source/Map/Submarine.cs +++ b/Barotrauma/BarotraumaShared/Source/Map/Submarine.cs @@ -1249,7 +1249,7 @@ namespace Barotrauma List items = new List(Item.ItemList); foreach (Item item in items) { - DebugConsole.ThrowError("Error while unloading submarines - item \""+item.Name+"\" not removed"); + DebugConsole.ThrowError("Error while unloading submarines - item \"" + item.Name + "\" (ID:" + item.ID + ") not removed"); try { item.Remove();