WIP Make collections thread-safe and add safe iteration
Replaced static lists and dictionaries with thread-safe ConcurrentDictionary or ThreadLocal collections for various item components and systems. Updated all relevant code to use snapshots (ToArray, ToList) for safe iteration, and added helper methods for marking and clearing changed connections. These changes improve thread safety and prevent potential concurrency issues in multi-threaded scenarios.
This commit is contained in:
@@ -949,7 +949,8 @@ namespace Barotrauma.Items.Components
|
||||
//if any of the effects reduce the item's condition, set the user for OnBroken effects as well
|
||||
if (reducesCondition && user != null && type != ActionType.OnBroken)
|
||||
{
|
||||
foreach (ItemComponent ic in item.Components)
|
||||
// Use ToArray() snapshot for thread-safe iteration
|
||||
foreach (ItemComponent ic in item.Components.ToArray())
|
||||
{
|
||||
if (ic.statusEffectLists == null || !ic.statusEffectLists.TryGetValue(ActionType.OnBroken, out List<StatusEffect> brokenEffects)) { continue; }
|
||||
foreach (var brokenEffect in brokenEffects)
|
||||
|
||||
Reference in New Issue
Block a user