From bcef118489e818e0e6d9cc159b817c7792a07161 Mon Sep 17 00:00:00 2001 From: Vera Aguilera Puerto Date: Mon, 7 Mar 2022 12:56:19 +0100 Subject: [PATCH] Extra checks in MindSystem entity deletion ghost spawning. I have a feeling this might be the cause of the round restart bugs, so make sure the round hasn't ended in the spawned timer code and log every ghost spawned by this. --- Content.Server/Mind/MindSystem.cs | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/Content.Server/Mind/MindSystem.cs b/Content.Server/Mind/MindSystem.cs index 997880cfaa..d8a3cdbae8 100644 --- a/Content.Server/Mind/MindSystem.cs +++ b/Content.Server/Mind/MindSystem.cs @@ -89,17 +89,24 @@ public sealed class MindSystem : EntitySystem // Use a regular timer here because the entity has probably been deleted. Timer.Spawn(0, () => { + // Make extra sure the round didn't end between spawning the timer and it being executed. + if (_gameTicker.RunLevel != GameRunLevel.InRound) + return; + // Async this so that we don't throw if the grid we're on is being deleted. var gridId = spawnPosition.GetGridId(EntityManager); - if (gridId == GridId.Invalid || !_mapManager.GridExists(gridId)) + if (!spawnPosition.IsValid(EntityManager) || gridId == GridId.Invalid || !_mapManager.GridExists(gridId)) { - spawnPosition = EntitySystem.Get().GetObserverSpawnPoint(); + spawnPosition = _gameTicker.GetObserverSpawnPoint(); } var ghost = Spawn("MobObserver", spawnPosition); var ghostComponent = Comp(ghost); _ghostSystem.SetCanReturnToBody(ghostComponent, false); + // Log these to make sure they're not causing the GameTicker round restart bugs... + Logger.DebugS("mind", $"Entity \"{ToPrettyString(uid)}\" for {mind.Mind?.CharacterName} was deleted, spawned \"{ToPrettyString(ghost)}\"."); + if (mind.Mind == null) return;