diff --git a/Subsurface/Source/Characters/Animation/Ragdoll.cs b/Subsurface/Source/Characters/Animation/Ragdoll.cs index d28c46fea..050bf0efc 100644 --- a/Subsurface/Source/Characters/Animation/Ragdoll.cs +++ b/Subsurface/Source/Characters/Animation/Ragdoll.cs @@ -1155,11 +1155,22 @@ namespace Barotrauma public void Remove() { - foreach (Limb l in Limbs) l.Remove(); + foreach (Limb l in Limbs) + { + l.Remove(); + } + Limbs = null; + + collider.Remove(); + collider = null; + foreach (RevoluteJoint joint in limbJoints) { GameMain.World.RemoveJoint(joint); } + limbJoints = null; + + list.Remove(this); } } diff --git a/Subsurface/Source/Characters/Character.cs b/Subsurface/Source/Characters/Character.cs index 0d5af0dc8..47f02ca4d 100644 --- a/Subsurface/Source/Characters/Character.cs +++ b/Subsurface/Source/Characters/Character.cs @@ -2142,6 +2142,8 @@ namespace Barotrauma if (aiTarget != null) aiTarget.Remove(); + if (Lights.LightManager.ViewTarget == this) Lights.LightManager.ViewTarget = null; + if (AnimController!=null) AnimController.Remove(); } diff --git a/Subsurface/Source/Characters/Limb.cs b/Subsurface/Source/Characters/Limb.cs index 348c84739..95445a17f 100644 --- a/Subsurface/Source/Characters/Limb.cs +++ b/Subsurface/Source/Characters/Limb.cs @@ -557,12 +557,29 @@ namespace Barotrauma public void Remove() { sprite.Remove(); - if (LightSource != null) LightSource.Remove(); - if (damagedSprite != null) damagedSprite.Remove(); + sprite = null; - body.Remove(); + if (LightSource != null) + { + LightSource.Remove(); + } + if (damagedSprite != null) + { + damagedSprite.Remove(); + damagedSprite = null; + } - if (hitSound != null) hitSound.Remove(); + if (body != null) + { + body.Remove(); + body = null; + } + + if (hitSound != null) + { + hitSound.Remove(); + hitSound = null; + } } } } diff --git a/Subsurface/Source/Map/Entity.cs b/Subsurface/Source/Map/Entity.cs index d77fd77de..75c241465 100644 --- a/Subsurface/Source/Map/Entity.cs +++ b/Subsurface/Source/Map/Entity.cs @@ -133,7 +133,14 @@ namespace Barotrauma List list = new List(dictionary.Values); foreach (Entity e in list) { - e.Remove(); + try + { + e.Remove(); + } + catch (Exception exception) + { + DebugConsole.ThrowError("Error while removing entity \"" + e.ToString() + "\"", exception); + } } dictionary.Clear(); } diff --git a/Subsurface/Source/Map/Hull.cs b/Subsurface/Source/Map/Hull.cs index 1d7a76708..055f82e46 100644 --- a/Subsurface/Source/Map/Hull.cs +++ b/Subsurface/Source/Map/Hull.cs @@ -334,7 +334,7 @@ namespace Barotrauma base.Remove(); hullList.Remove(this); - if (Submarine == null || !Submarine.Loading) + if (Submarine == null || (!Submarine.Loading && !Submarine.Unloading)) { Item.UpdateHulls(); Gap.UpdateHulls();