]> git.smokeofanarchy.ru Git - space-station-14.git/commitdiff
Fix error when starting a DoAfter while handling one on the same entity (#24218)
authorDrSmugleaf <DrSmugleaf@users.noreply.github.com>
Thu, 18 Jan 2024 08:01:58 +0000 (00:01 -0800)
committerGitHub <noreply@github.com>
Thu, 18 Jan 2024 08:01:58 +0000 (00:01 -0800)
* Fix error when starting a DoAfter while handling one on the same entity

* Reuse array

Content.Shared/DoAfter/SharedDoAfterSystem.Update.cs

index 32f46e5791ba364f0eb89cfe28b7d805a49ec24e..abd8888f583f9d1b64679d7617762aefc9742633 100644 (file)
@@ -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<DoAfter>();
+
     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)