Files
Eero caec44c57d 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.
2026-01-08 00:26:29 +08:00

26 lines
961 B
C#

#nullable enable
using Barotrauma.Networking;
using System.Collections.Generic;
using System.Linq;
namespace Barotrauma;
partial class HighlightAction : EventAction
{
partial void SetHighlightProjSpecific(Entity entity, IEnumerable<Character>? targetCharacters)
{
if (entity is Item item && GameMain.Server != null)
{
IEnumerable<Client>? targetClients = null;
if (targetCharacters != null)
{
// Create snapshot to avoid concurrent access issues during parallel updates
var clients = GameMain.Server.ConnectedClients.ToArray();
targetClients = targetCharacters
.Select(c => clients.FirstOrDefault(client => client.Character == c))
.Where(c => c != null)!;
}
GameMain.Server?.CreateEntityEvent(item, new Item.SetHighlightEventData(State, highlightColor, targetClients));
}
}
}