Unstable Add thread-safe queue for deferred physics body creation
Introduces PhysicsBodyQueue to safely defer physics body creation to the main thread, addressing thread-safety issues with Farseer Physics during parallel updates. Updates LevelResource, TriggerComponent, BallastFloraBehavior, and MapEntity to use the queue for all physics body creation and refresh operations, ensuring they are processed outside of parallel loops. Also adds cleanup of the queue at round end.
This commit is contained in:
@@ -686,6 +686,10 @@ namespace Barotrauma
|
||||
}
|
||||
);
|
||||
|
||||
// Process any physics body creation operations queued during Hull/Structure updates.
|
||||
// BallastFlora growth (from Hull.Update) may queue physics body creations.
|
||||
PhysicsBodyQueue.ProcessPendingCreations();
|
||||
|
||||
#if CLIENT
|
||||
// Hull Cheats need to be executed after Hull update
|
||||
Hull.UpdateCheats(deltaTime, cam);
|
||||
@@ -727,6 +731,10 @@ namespace Barotrauma
|
||||
throw new InvalidOperationException($"Error while updating item {lastUpdatedItem?.Name ?? "null"}", innerException: e);
|
||||
}
|
||||
|
||||
// Process any physics body creation operations that were queued during the parallel update.
|
||||
// This must be done on the main thread because Farseer Physics is not thread-safe.
|
||||
PhysicsBodyQueue.ProcessPendingCreations();
|
||||
|
||||
UpdateAllProjSpecific(scaledDeltaTime);
|
||||
Spawner?.Update();
|
||||
|
||||
|
||||
Reference in New Issue
Block a user