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:
+8
-3
@@ -1,3 +1,5 @@
|
||||
using System.Linq;
|
||||
|
||||
namespace Barotrauma
|
||||
{
|
||||
partial class EventObjectiveAction : EventAction
|
||||
@@ -13,9 +15,12 @@ namespace Barotrauma
|
||||
ParentObjectiveId,
|
||||
CanBeCompleted);
|
||||
|
||||
// Create snapshot to avoid concurrent access issues during parallel updates
|
||||
var clients = GameMain.Server.ConnectedClients.ToArray();
|
||||
|
||||
if (TargetTag.IsEmpty)
|
||||
{
|
||||
foreach (var client in GameMain.Server.ConnectedClients)
|
||||
foreach (var client in clients)
|
||||
{
|
||||
if (client.Character == null) { continue; }
|
||||
EventManager.ServerWriteObjective(client, objective);
|
||||
@@ -26,11 +31,11 @@ namespace Barotrauma
|
||||
foreach (var target in ParentEvent.GetTargets(TargetTag))
|
||||
{
|
||||
if (target is not Character character) { continue; }
|
||||
var ownerClient = GameMain.Server.ConnectedClients.Find(c => c.Character == character);
|
||||
var ownerClient = clients.FirstOrDefault(c => c.Character == character);
|
||||
if (ownerClient == null) { continue; }
|
||||
EventManager.ServerWriteObjective(ownerClient, objective);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user