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:
@@ -76,7 +76,9 @@ namespace Barotrauma.Items.Components
|
||||
{
|
||||
var (msg, deliveryMethod) = PrepareToSend(opcode, data);
|
||||
|
||||
foreach (Client client in GameMain.Server.ConnectedClients)
|
||||
// Create snapshot to avoid concurrent access issues during parallel updates
|
||||
var clients = GameMain.Server.ConnectedClients.ToArray();
|
||||
foreach (Client client in clients)
|
||||
{
|
||||
if (predicate is not null && !predicate(client)) { continue; }
|
||||
|
||||
@@ -391,4 +393,4 @@ namespace Barotrauma.Items.Components
|
||||
CreateServerEvent(new CircuitBoxServerUpdateSelection(nodes, wires, ios, labels));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user