From: DrSmugleaf Date: Thu, 18 Jan 2024 08:01:58 +0000 (-0800) Subject: Fix error when starting a DoAfter while handling one on the same entity (#24218) X-Git-Url: https://git.smokeofanarchy.ru/gitweb.cgi?a=commitdiff_plain;h=9ad1ae5d963cf294d2f68d06ce07506dedbefe64;p=space-station-14.git Fix error when starting a DoAfter while handling one on the same entity (#24218) * Fix error when starting a DoAfter while handling one on the same entity * Reuse array --- diff --git a/Content.Shared/DoAfter/SharedDoAfterSystem.Update.cs b/Content.Shared/DoAfter/SharedDoAfterSystem.Update.cs index 32f46e5791..abd8888f58 100644 --- a/Content.Shared/DoAfter/SharedDoAfterSystem.Update.cs +++ b/Content.Shared/DoAfter/SharedDoAfterSystem.Update.cs @@ -9,6 +9,8 @@ public abstract partial class SharedDoAfterSystem : EntitySystem [Dependency] private readonly IDynamicTypeFactory _factory = default!; [Dependency] private readonly SharedGravitySystem _gravity = default!; + private DoAfter[] _doAfters = Array.Empty(); + public override void Update(float frameTime) { base.Update(frameTime); @@ -34,8 +36,15 @@ public abstract partial class SharedDoAfterSystem : EntitySystem { var dirty = false; - foreach (var doAfter in comp.DoAfters.Values) + var values = comp.DoAfters.Values; + var count = values.Count; + if (_doAfters.Length < count) + _doAfters = new DoAfter[count]; + + values.CopyTo(_doAfters, 0); + for (var i = 0; i < count; i++) { + var doAfter = _doAfters[i]; if (doAfter.CancelledTime != null) { if (time - doAfter.CancelledTime.Value > ExcessTime)