Skip to content

Commit

Permalink
Merge stable into master: Hotfix the randomly occurring DeleteAllThen…
Browse files Browse the repository at this point in the history
…Ghost test failures (space-wizards#33593)
  • Loading branch information
VasilisThePikachu authored Nov 27, 2024
2 parents 1b6c9e8 + eb95403 commit 1bc6562
Showing 1 changed file with 14 additions and 4 deletions.
18 changes: 14 additions & 4 deletions Content.Shared/Roles/SharedRoleSystem.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
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;
Expand All @@ -20,14 +19,15 @@ 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;

public override void Initialize()
{
Subs.CVar(_cfg, CCVars.GameRoleTimerOverride, SetRequirementOverride, true);

SubscribeLocalEvent<MindRoleComponent, ComponentShutdown>(OnComponentShutdown);
}

private void SetRequirementOverride(string value)
Expand Down Expand Up @@ -209,7 +209,6 @@ public bool MindRemoveRole<T>(Entity<MindComponent?> mind) where T : IComponent
}

antagonist |= roleComp.Antag | roleComp.ExclusiveAntag;
_entityManager.DeleteEntity(role);
delete.Add(role);
found = true;
}
Expand All @@ -219,7 +218,7 @@ public bool MindRemoveRole<T>(Entity<MindComponent?> mind) where T : IComponent

foreach (var role in delete)
{
mind.Comp.MindRoles.Remove(role);
_entityManager.DeleteEntity(role);
}

if (mind.Comp.OwnedEntity != null)
Expand All @@ -235,6 +234,17 @@ public bool MindRemoveRole<T>(Entity<MindComponent?> mind) where T : IComponent
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<MindRoleComponent> 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);
}

/// <summary>
/// Finds and removes all mind roles of a specific type
/// </summary>
Expand Down

0 comments on commit 1bc6562

Please sign in to comment.