Skip to content

Commit

Permalink
Emergency Bugfix #2
Browse files Browse the repository at this point in the history
  • Loading branch information
ari-steas committed May 22, 2024
1 parent 49f6cc4 commit 3e2b1ef
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 11 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,11 @@ public PhysicalAssembly MemberAssembly
}
}

internal void RemoveAssemblyUnsafe()
{
_memberAssembly = null;
}

private HashSet<PhysicalAssembly> _bufferNeighborAssemblies = new HashSet<PhysicalAssembly>();
public void DoConnectionCheck(bool cascadingUpdate = false)
{
Expand All @@ -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();
}
Expand Down Expand Up @@ -120,7 +125,6 @@ public void DoConnectionCheck(bool cascadingUpdate = false)

neighbor.DoConnectionCheck(true);
}

}

_bufferNeighborAssemblies.Clear();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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;
Expand All @@ -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);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -112,26 +112,28 @@ 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)
{
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()
Expand Down

0 comments on commit 3e2b1ef

Please sign in to comment.