]> git.smokeofanarchy.ru Git - space-station-14.git/commitdiff
Fix AtmosDeviceSystem debug assert Heisenbug (#29752)
authorTayrtahn <tayrtahn@gmail.com>
Thu, 11 Jul 2024 06:14:34 +0000 (02:14 -0400)
committerGitHub <noreply@github.com>
Thu, 11 Jul 2024 06:14:34 +0000 (16:14 +1000)
Fix AtmosDeviceSystem debug assertion Heisenbug

Content.IntegrationTests/Tests/Atmos/GridJoinTest.cs [new file with mode: 0644]
Content.Server/Atmos/Piping/EntitySystems/AtmosDeviceSystem.cs

diff --git a/Content.IntegrationTests/Tests/Atmos/GridJoinTest.cs b/Content.IntegrationTests/Tests/Atmos/GridJoinTest.cs
new file mode 100644 (file)
index 0000000..3a1ec7f
--- /dev/null
@@ -0,0 +1,53 @@
+using Content.Server.Atmos.Components;
+using Content.Server.Atmos.EntitySystems;
+using Content.Server.Atmos.Piping.Components;
+using Content.Server.Atmos.Piping.EntitySystems;
+using Robust.Shared.GameObjects;
+
+namespace Content.IntegrationTests.Tests.Atmos;
+
+[TestFixture]
+public sealed class GridJoinTest
+{
+    private const string CanisterProtoId = "AirCanister";
+
+    [Test]
+    public async Task TestGridJoinAtmosphere()
+    {
+        await using var pair = await PoolManager.GetServerClient();
+        var server = pair.Server;
+
+        var entMan = server.EntMan;
+        var protoMan = server.ProtoMan;
+        var atmosSystem = entMan.System<AtmosphereSystem>();
+        var atmosDeviceSystem = entMan.System<AtmosDeviceSystem>();
+        var transformSystem = entMan.System<SharedTransformSystem>();
+
+        var testMap = await pair.CreateTestMap();
+
+        await server.WaitPost(() =>
+        {
+            // Spawn an atmos device on the grid
+            var canister = entMan.Spawn(CanisterProtoId);
+            transformSystem.SetCoordinates(canister, testMap.GridCoords);
+            var deviceComp = entMan.GetComponent<AtmosDeviceComponent>(canister);
+            var canisterEnt = (canister, deviceComp);
+
+            // Make sure the canister is tracked as an off-grid device
+            Assert.That(atmosDeviceSystem.IsJoinedOffGrid(canisterEnt));
+
+            // Add an atmosphere to the grid
+            entMan.AddComponent<GridAtmosphereComponent>(testMap.Grid);
+
+            // Force AtmosDeviceSystem to update off-grid devices
+            // This means the canister is now considered on-grid,
+            // but it's still tracked as off-grid!
+            Assert.DoesNotThrow(() => atmosDeviceSystem.Update(atmosSystem.AtmosTime));
+
+            // Make sure that the canister is now properly tracked as on-grid
+            Assert.That(atmosDeviceSystem.IsJoinedOffGrid(canisterEnt), Is.False);
+        });
+
+        await pair.CleanReturnAsync();
+    }
+}
index 3c73a8f64ee916e96829ef807a16f1fcae941667..f932ef36208e5e4c89487fb2a1d797871074ae31 100644 (file)
@@ -132,10 +132,19 @@ namespace Content.Server.Atmos.Piping.EntitySystems
             var ev = new AtmosDeviceUpdateEvent(_atmosphereSystem.AtmosTime, null, null);
             foreach (var device in _joinedDevices)
             {
-                DebugTools.Assert(!HasComp<GridAtmosphereComponent>(Transform(device).GridUid));
+                var deviceGrid = Transform(device).GridUid;
+                if (HasComp<GridAtmosphereComponent>(deviceGrid))
+                {
+                    RejoinAtmosphere(device);
+                }
                 RaiseLocalEvent(device, ref ev);
                 device.Comp.LastProcess = time;
             }
         }
+
+        public bool IsJoinedOffGrid(Entity<AtmosDeviceComponent> device)
+        {
+            return _joinedDevices.Contains(device);
+        }
     }
 }