Fix concurrent access issues with ConnectedClients

Replaced direct access to GameMain.Server.ConnectedClients with array snapshots in multiple server-side classes to prevent concurrent modification issues during parallel updates. Also updated PhysicsBody and LevelTrigger to avoid static/shared state in parallel contexts, improving thread safety and reliability.
This commit is contained in:
Eero
2026-01-08 00:26:29 +08:00
parent f4a0d149ca
commit caec44c57d
13 changed files with 108 additions and 59 deletions
@@ -834,6 +834,12 @@ namespace Barotrauma
if (!IsValidValue(simPosition, "position", -1e10f, 1e10f)) { return false; }
if (!IsValidValue(rotation, "rotation")) { return false; }
if (PhysicsBodyQueue.IsInParallelContext)
{
PhysicsBodyQueue.Enqueue(() => SetTransform(simPosition, rotation, setPrevTransform));
return true;
}
FarseerBody.SetTransform(simPosition, rotation);
if (setPrevTransform) { SetPrevTransform(simPosition, rotation); }
return true;
@@ -848,6 +854,12 @@ namespace Barotrauma
if (!IsValidValue(simPosition, "position", -1e10f, 1e10f)) { return false; }
if (!IsValidValue(rotation, "rotation")) { return false; }
if (PhysicsBodyQueue.IsInParallelContext)
{
PhysicsBodyQueue.Enqueue(() => SetTransformIgnoreContacts(simPosition, rotation, setPrevTransform));
return true;
}
FarseerBody.SetTransformIgnoreContacts(ref simPosition, rotation);
if (setPrevTransform) { SetPrevTransform(simPosition, rotation); }
return true;