From 3e2b1ef57d76484d8aa3878f7c661f01d4065944 Mon Sep 17 00:00:00 2001 From: Aristeas <94058548+Jnick-24@users.noreply.github.com> Date: Tue, 21 May 2024 23:50:05 -0500 Subject: [PATCH] Emergency Bugfix #2 --- .../AssemblyComponents/AssemblyPart.cs | 8 ++++++-- .../AssemblyComponents/GridAssemblyLogic.cs | 7 ++++--- .../AssemblyComponents/PhysicalAssembly.cs | 14 ++++++++------ 3 files changed, 18 insertions(+), 11 deletions(-) diff --git a/Data/Scripts/AssemblyScripts/AssemblyComponents/AssemblyPart.cs b/Data/Scripts/AssemblyScripts/AssemblyComponents/AssemblyPart.cs index 0bfc89c..1ccbb34 100644 --- a/Data/Scripts/AssemblyScripts/AssemblyComponents/AssemblyPart.cs +++ b/Data/Scripts/AssemblyScripts/AssemblyComponents/AssemblyPart.cs @@ -51,6 +51,11 @@ public PhysicalAssembly MemberAssembly } } + internal void RemoveAssemblyUnsafe() + { + _memberAssembly = null; + } + private HashSet _bufferNeighborAssemblies = new HashSet(); public void DoConnectionCheck(bool cascadingUpdate = false) { @@ -73,7 +78,7 @@ public void DoConnectionCheck(bool cascadingUpdate = false) foreach (var neighbor in ConnectedParts) { - if (neighbor.MemberAssembly != null && neighbor.MemberAssembly.ComponentParts != null) + if (neighbor.MemberAssembly?.ComponentParts != null) _bufferNeighborAssemblies.Add(neighbor.MemberAssembly); neighbor.ConnectedParts = neighbor.GetValidNeighborParts(); } @@ -120,7 +125,6 @@ public void DoConnectionCheck(bool cascadingUpdate = false) neighbor.DoConnectionCheck(true); } - } _bufferNeighborAssemblies.Clear(); diff --git a/Data/Scripts/AssemblyScripts/AssemblyComponents/GridAssemblyLogic.cs b/Data/Scripts/AssemblyScripts/AssemblyComponents/GridAssemblyLogic.cs index fcd438c..3bb2d4a 100644 --- a/Data/Scripts/AssemblyScripts/AssemblyComponents/GridAssemblyLogic.cs +++ b/Data/Scripts/AssemblyScripts/AssemblyComponents/GridAssemblyLogic.cs @@ -82,7 +82,7 @@ private void OnGridSplit(MyCubeGrid thisGrid, MyCubeGrid newGrid) private void OnBlockAdd(IMySlimBlock block) { - if (block == null || block.FatBlock == null) + if (block?.FatBlock == null) return; try @@ -103,8 +103,7 @@ private void OnBlockAdd(IMySlimBlock block) } } - private void - OnBlockRemove(IMySlimBlock block) // TODO: Maintain assemblies between grid split, unless directly affected. + private void OnBlockRemove(IMySlimBlock block) { if (block?.FatBlock == null) return; @@ -117,9 +116,11 @@ private void { if ((block.IsMovedBySplit || block.CubeGrid.WillRemoveBlockSplitGrid(block)) && part.MemberAssembly?.ComponentParts != null) + { if (!SplitAssemblies.ContainsKey(part.MemberAssembly.AssemblyId)) SplitAssemblies.Add(part.MemberAssembly.AssemblyId, new AssemblySerializer.AssemblyStorage(part.MemberAssembly, true)); + } part.PartRemoved(); AllAssemblyParts[part.AssemblyDefinition].Remove(block); diff --git a/Data/Scripts/AssemblyScripts/AssemblyComponents/PhysicalAssembly.cs b/Data/Scripts/AssemblyScripts/AssemblyComponents/PhysicalAssembly.cs index 3987462..e028f1c 100644 --- a/Data/Scripts/AssemblyScripts/AssemblyComponents/PhysicalAssembly.cs +++ b/Data/Scripts/AssemblyScripts/AssemblyComponents/PhysicalAssembly.cs @@ -112,7 +112,7 @@ public void RemovePart(AssemblyPart part) if (partLoops.Count <= 1) return; - + ModularLog.Log("Doing loop check."); // Split apart, keeping this assembly as the largest loop. var largestLoop = partLoops[0]; foreach (var loop in partLoops) @@ -120,18 +120,20 @@ public void RemovePart(AssemblyPart part) if (loop.Count > largestLoop.Count) largestLoop = loop; } + ModularLog.Log("| " + largestLoop.Count); foreach (var componentPart in _componentParts.ToArray()) { if (largestLoop.Contains(componentPart)) continue; - if (_componentParts?.Remove(componentPart) ?? false) - { - ComponentParts = _componentParts?.ToArray(); - AssemblyPartManager.I.QueueConnectionCheck(componentPart); - } + if (!_componentParts.Remove(componentPart)) + continue; + componentPart.RemoveAssemblyUnsafe(); + AssemblyPartManager.I.QueueConnectionCheck(componentPart); } + + ComponentParts = _componentParts?.ToArray(); } public void Close()