diff --git a/Subsurface/Source/Characters/AI/PathFinder.cs b/Subsurface/Source/Characters/AI/PathFinder.cs index 78846b22c..f01d1b89c 100644 --- a/Subsurface/Source/Characters/AI/PathFinder.cs +++ b/Subsurface/Source/Characters/AI/PathFinder.cs @@ -45,6 +45,12 @@ namespace Barotrauma var nodes = new Dictionary(); foreach (WayPoint wayPoint in wayPoints) { + if (wayPoint == null) continue; + if (nodes.ContainsKey(wayPoint.ID)) + { + DebugConsole.ThrowError("Error in PathFinder.GenerateNodes (duplicate ID \"" + wayPoint.ID + "\")"); + continue; + } nodes.Add(wayPoint.ID, new PathNode(wayPoint)); } diff --git a/Subsurface/Source/Map/Gap.cs b/Subsurface/Source/Map/Gap.cs index 0724fae4e..f91af9527 100644 --- a/Subsurface/Source/Map/Gap.cs +++ b/Subsurface/Source/Map/Gap.cs @@ -670,19 +670,27 @@ namespace Barotrauma return null; } - public override void Remove() + public override void ShallowRemove() { - base.Remove(); - + base.ShallowRemove(); GapList.Remove(this); foreach (Hull hull in Hull.hullList) { hull.ConnectedGaps.Remove(this); } - } + public override void Remove() + { + base.Remove(); + GapList.Remove(this); + + foreach (Hull hull in Hull.hullList) + { + hull.ConnectedGaps.Remove(this); + } + } public override void OnMapLoaded() { diff --git a/Subsurface/Source/Map/Hull.cs b/Subsurface/Source/Map/Hull.cs index d2e30446a..e92b77ad6 100644 --- a/Subsurface/Source/Map/Hull.cs +++ b/Subsurface/Source/Map/Hull.cs @@ -332,6 +332,39 @@ namespace Barotrauma Pressure = surface; } + public override void ShallowRemove() + { + base.Remove(); + hullList.Remove(this); + + if (Submarine == null || (!Submarine.Loading && !Submarine.Unloading)) + { + Item.UpdateHulls(); + Gap.UpdateHulls(); + } + + List fireSourcesToRemove = new List(fireSources); + foreach (FireSource fireSource in fireSourcesToRemove) + { + fireSource.Remove(); + } + fireSources.Clear(); + + if (soundIndex > -1) + { + Sounds.SoundManager.Stop(soundIndex); + soundIndex = -1; + } + + if (entityGrids != null) + { + foreach (EntityGrid entityGrid in entityGrids) + { + entityGrid.RemoveEntity(this); + } + } + } + public override void Remove() { base.Remove(); @@ -355,8 +388,7 @@ namespace Barotrauma Sounds.SoundManager.Stop(soundIndex); soundIndex = -1; } - - //renderer.Dispose(); + if (entityGrids != null) { foreach (EntityGrid entityGrid in entityGrids) diff --git a/Subsurface/Source/Map/Structure.cs b/Subsurface/Source/Map/Structure.cs index 39eaa4e99..1ec5885a4 100644 --- a/Subsurface/Source/Map/Structure.cs +++ b/Subsurface/Source/Map/Structure.cs @@ -452,7 +452,34 @@ namespace Barotrauma } } } - + + public override void ShallowRemove() + { + base.ShallowRemove(); + + if (WallList.Contains(this)) WallList.Remove(this); + + if (bodies != null) + { + foreach (Body b in bodies) + GameMain.World.RemoveBody(b); + } + + if (sections != null) + { + foreach (WallSection s in sections) + { + if (s.gap != null) + { + s.gap.Remove(); + s.gap = null; + } + } + } + + if (convexHulls != null) convexHulls.ForEach(x => x.Remove()); + } + public override void Remove() { base.Remove(); diff --git a/Subsurface/Source/Map/WayPoint.cs b/Subsurface/Source/Map/WayPoint.cs index fcaf02b5c..8e7417812 100644 --- a/Subsurface/Source/Map/WayPoint.cs +++ b/Subsurface/Source/Map/WayPoint.cs @@ -820,6 +820,13 @@ namespace Barotrauma } } + public override void ShallowRemove() + { + base.ShallowRemove(); + + WayPointList.Remove(this); + } + public override void Remove() { base.Remove();