From 3aadff7a3c8f63a824ebe4c4ef3cb63444332ae6 Mon Sep 17 00:00:00 2001 From: NotAlwaysTrue <2136846186@qq.com> Date: Sat, 27 Dec 2025 15:51:04 +0800 Subject: [PATCH] Improved thread safety for Gap.update() --- Barotrauma/BarotraumaShared/SharedSource/Map/Gap.cs | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/Barotrauma/BarotraumaShared/SharedSource/Map/Gap.cs b/Barotrauma/BarotraumaShared/SharedSource/Map/Gap.cs index 94b8bd03e..3fe156958 100644 --- a/Barotrauma/BarotraumaShared/SharedSource/Map/Gap.cs +++ b/Barotrauma/BarotraumaShared/SharedSource/Map/Gap.cs @@ -3,11 +3,12 @@ using Barotrauma.Items.Components; using FarseerPhysics; using FarseerPhysics.Dynamics; using Microsoft.Xna.Framework; +using MoonSharp.Interpreter; using System; +using System.Collections.Concurrent; using System.Collections.Generic; using System.Linq; using System.Xml.Linq; -using MoonSharp.Interpreter; namespace Barotrauma { @@ -745,7 +746,7 @@ namespace Barotrauma waterFlowThisFrame = 0.0f; } - private static readonly HashSet checkedHulls = new HashSet(); + private static readonly ConcurrentBag checkedHulls = new ConcurrentBag(); /// /// Simulates water flow from the source to all the hulls it's connected to across the sub, as if the water was coming directly from outside. @@ -764,7 +765,7 @@ namespace Barotrauma } } - static void SimulateWaterFlowFromOutsideToConnectedHullsRecursive(Hull targetHull, Gap gap, HashSet checkedHulls, Hull originHull, float maxFlow, float deltaTime) + static void SimulateWaterFlowFromOutsideToConnectedHullsRecursive(Hull targetHull, Gap gap, ConcurrentBag checkedHulls, Hull originHull, float maxFlow, float deltaTime) { const float decay = 0.95f;