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.
This commit is contained in:
Vera Aguilera Puerto 2022-03-07 12:56:19 +01:00
parent 4a3c276123
commit bcef118489
1 changed files with 9 additions and 2 deletions

View File

@ -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<GameTicker>().GetObserverSpawnPoint();
spawnPosition = _gameTicker.GetObserverSpawnPoint();
}
var ghost = Spawn("MobObserver", spawnPosition);
var ghostComponent = Comp<GhostComponent>(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;