Skip to content

Commit

Permalink
Re-attempt FlushEntities() on failure (#5423)
Browse files Browse the repository at this point in the history
  • Loading branch information
ElectroJr authored Sep 6, 2024
1 parent be9db26 commit 405ed37
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 7 deletions.
2 changes: 1 addition & 1 deletion RELEASE-NOTES.md
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ END TEMPLATE-->

### Other

*None yet*
* If `EntityManager.FlushEntities()` fails to delete all entities, it will now attempt to do so a second time before throwing an exception.

### Internal

Expand Down
3 changes: 2 additions & 1 deletion Robust.Server/GameStates/PvsSystem.DataStorage.cs
Original file line number Diff line number Diff line change
Expand Up @@ -300,7 +300,8 @@ private void OnEntityDeleted(Entity<MetaDataComponent> entity)
/// </summary>
private void AfterEntityFlush()
{
DebugTools.Assert(EntityManager.EntityCount == 0);
if (EntityManager.EntityCount > 0)
throw new Exception("Cannot reset PVS data without first deleting all entities.");

ClearPvsData();
ShrinkDataMemory();
Expand Down
24 changes: 19 additions & 5 deletions Robust.Shared/GameObjects/EntityManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -693,6 +693,25 @@ public bool Deleted([NotNullWhen(false)] EntityUid? uid)
public virtual void FlushEntities()
{
BeforeEntityFlush?.Invoke();
FlushEntitiesInternal();

if (Entities.Count != 0)
_sawmill.Error("Failed to flush all entities");

#if EXCEPTION_TOLERANCE
// Attempt to flush entities a second time, just in case something somehow caused an entity to be spawned
// while flushing entities
FlushEntitiesInternal();
#endif

if (Entities.Count != 0)
throw new Exception("Failed to flush all entities");

AfterEntityFlush?.Invoke();
}

private void FlushEntitiesInternal()
{
QueuedDeletions.Clear();
QueuedDeletionsSet.Clear();

Expand Down Expand Up @@ -738,11 +757,6 @@ public virtual void FlushEntities()
#endif
}
}

if (Entities.Count != 0)
_sawmill.Error("Entities were spawned while flushing entities.");

AfterEntityFlush?.Invoke();
}

/// <summary>
Expand Down

0 comments on commit 405ed37

Please sign in to comment.