Fixed timer crash once for all - yes it was a race condition

This commit is contained in:
EvilFactory
2023-01-17 14:17:43 -03:00
parent 17d125e6d5
commit 2073cdf5e5
@@ -60,6 +60,8 @@ namespace Barotrauma
throw new ArgumentNullException(nameof(timedAction)); throw new ArgumentNullException(nameof(timedAction));
} }
lock (timedActions)
{
int insertionPoint = timedActions.BinarySearch(timedAction, new TimerComparer()); int insertionPoint = timedActions.BinarySearch(timedAction, new TimerComparer());
if (insertionPoint < 0) if (insertionPoint < 0)
@@ -69,8 +71,11 @@ namespace Barotrauma
timedActions.Insert(insertionPoint, timedAction); timedActions.Insert(insertionPoint, timedAction);
} }
}
public void Update() public void Update()
{
lock (timedActions)
{ {
TimedAction[] timedCopy = timedActions.ToArray(); TimedAction[] timedCopy = timedActions.ToArray();
for (int i = 0; i < timedCopy.Length; i++) for (int i = 0; i < timedCopy.Length; i++)
@@ -95,6 +100,7 @@ namespace Barotrauma
} }
} }
} }
}
public void Clear() public void Clear()
{ {