From 2947b33481b222fa24a21f3c1e44cc1f8933ec8f Mon Sep 17 00:00:00 2001 From: Leon Friedrich <60421075+ElectroJr@users.noreply.github.com> Date: Sat, 15 Jan 2022 05:26:52 +1300 Subject: [PATCH] Fix cable unanchor bug (#6159) --- Content.Server/Power/EntitySystems/CableSystem.cs | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/Content.Server/Power/EntitySystems/CableSystem.cs b/Content.Server/Power/EntitySystems/CableSystem.cs index f397a49c44..bb5927a7ca 100644 --- a/Content.Server/Power/EntitySystems/CableSystem.cs +++ b/Content.Server/Power/EntitySystems/CableSystem.cs @@ -37,7 +37,7 @@ public class CableSystem : EntitySystem return; Spawn(cable.CableDroppedOnCutPrototype, Transform(uid).Coordinates); - Del(uid); + QueueDel(uid); } private void OnAnchorChanged(EntityUid uid, CableComponent cable, ref AnchorStateChangedEvent args) @@ -45,10 +45,15 @@ public class CableSystem : EntitySystem if (args.Anchored) return; // huh? it wasn't anchored? + // anchor state can change as a result of deletion (detach to null). + // We don't want to spawn an entity when deleted. + if (!TryLifeStage(uid, out var life) || life >= EntityLifeStage.Terminating) + return; + // This entity should not be un-anchorable. But this can happen if the grid-tile is deleted (RCD, explosion, // etc). In that case: behave as if the cable had been cut. Spawn(cable.CableDroppedOnCutPrototype, Transform(uid).Coordinates); - Del(uid); + QueueDel(uid); } }