From 3517de177697cef03c6cf1dcfd801a6ca26bd8af Mon Sep 17 00:00:00 2001 From: Whatstone <166147148+whatston3@users.noreply.github.com> Date: Tue, 15 Oct 2024 18:41:52 -0400 Subject: [PATCH] DeadDropSystem: check lifecycle and null refs on compromise. (#2251) * DeadDropSystem: compromise checks teardown * DeadDropSystem: check teardown --- .../_NF/Smuggling/DeadDropSystem.cs | 19 ++++++++++++++++--- 1 file changed, 16 insertions(+), 3 deletions(-) diff --git a/Content.Server/_NF/Smuggling/DeadDropSystem.cs b/Content.Server/_NF/Smuggling/DeadDropSystem.cs index 6a05747fec8..bafbdaf098d 100644 --- a/Content.Server/_NF/Smuggling/DeadDropSystem.cs +++ b/Content.Server/_NF/Smuggling/DeadDropSystem.cs @@ -195,11 +195,18 @@ private void OnStationShutdown(EntityUid stationUid, StationDeadDropComponent co public void CompromiseDeadDrop(EntityUid uid, DeadDropComponent _) { - //Get our station: FIXME - check lifecycle on entities before adding another drop. + // Remove the dead drop. + RemComp(uid); + var station = _station.GetOwningStation(uid); + // If station is terminating, or if we aren't on one, nothing to do here. + if (station == null || + !station.Value.Valid || + MetaData(station.Value).EntityLifeStage >= EntityLifeStage.Terminating) + { + return; + } - //Remove the dead drop. - RemComp(uid); //Find a new potential dead drop to spawn. var deadDropQuery = EntityManager.EntityQueryEnumerator(); List<(EntityUid ent, PotentialDeadDropComponent comp)> potentialDeadDrops = new(); @@ -220,6 +227,12 @@ public void CompromiseDeadDrop(EntityUid uid, DeadDropComponent _) if (potentialDeadDrops.Count > 0) { var item = _random.Pick(potentialDeadDrops); + + // If the item is tearing down, do nothing for now. + // FIXME: separate sector-wide scheduler? + if (MetaData(item.ent).EntityLifeStage >= EntityLifeStage.Terminating) + return; + AddDeadDrop(item.ent); _sawmill.Debug($"Dead drop at {uid} compromised, new drop at {item.ent}!"); }