From: Errant <35878406+Errant-4@users.noreply.github.com> Date: Tue, 26 Nov 2024 23:56:35 +0000 (+0100) Subject: Hotfix the randomly occurring DeleteAllThenGhost test failures (#33582) X-Git-Url: https://git.smokeofanarchy.ru/gitweb.cgi?a=commitdiff_plain;h=eb9540364edbe56a9b63ea7c08bc0aef80167593;p=space-station-14.git Hotfix the randomly occurring DeleteAllThenGhost test failures (#33582) * clear mindrole on component shutdown * let it go --- diff --git a/Content.Shared/Roles/SharedRoleSystem.cs b/Content.Shared/Roles/SharedRoleSystem.cs index 00271693ab..d5820ac039 100644 --- a/Content.Shared/Roles/SharedRoleSystem.cs +++ b/Content.Shared/Roles/SharedRoleSystem.cs @@ -2,7 +2,6 @@ using System.Diagnostics.CodeAnalysis; using Content.Shared.Administration.Logs; using Content.Shared.CCVar; using Content.Shared.Database; -using Content.Shared.GameTicking; using Content.Shared.Mind; using Content.Shared.Roles.Jobs; using Robust.Shared.Audio; @@ -20,7 +19,6 @@ public abstract class SharedRoleSystem : EntitySystem [Dependency] private readonly SharedAudioSystem _audio = default!; [Dependency] private readonly IConfigurationManager _cfg = default!; [Dependency] private readonly IEntityManager _entityManager = default!; - [Dependency] private readonly SharedGameTicker _gameTicker = default!; [Dependency] private readonly IPrototypeManager _prototypes = default!; private JobRequirementOverridePrototype? _requirementOverride; @@ -28,6 +26,8 @@ public abstract class SharedRoleSystem : EntitySystem public override void Initialize() { Subs.CVar(_cfg, CCVars.GameRoleTimerOverride, SetRequirementOverride, true); + + SubscribeLocalEvent(OnComponentShutdown); } private void SetRequirementOverride(string value) @@ -209,7 +209,6 @@ public abstract class SharedRoleSystem : EntitySystem } antagonist |= roleComp.Antag | roleComp.ExclusiveAntag; - _entityManager.DeleteEntity(role); delete.Add(role); found = true; } @@ -219,7 +218,7 @@ public abstract class SharedRoleSystem : EntitySystem foreach (var role in delete) { - mind.Comp.MindRoles.Remove(role); + _entityManager.DeleteEntity(role); } if (mind.Comp.OwnedEntity != null) @@ -235,6 +234,17 @@ public abstract class SharedRoleSystem : EntitySystem return true; } + // Removing the mind role's reference on component shutdown + // to make sure the reference gets removed even if the mind role entity was deleted by outside code + private void OnComponentShutdown(Entity ent, ref ComponentShutdown args) + { + //TODO: Just ensure that the tests don't spawn unassociated mind role entities + if (ent.Comp.Mind.Comp is null) + return; + + ent.Comp.Mind.Comp.MindRoles.Remove(ent.Owner); + } + /// /// Finds and removes all mind roles of a specific type ///