From 381c856dd4c65598e055ad911835738b5ee875aa Mon Sep 17 00:00:00 2001 From: Leon Friedrich <60421075+ElectroJr@users.noreply.github.com> Date: Mon, 1 May 2023 16:11:21 +1200 Subject: [PATCH] Add transform recursion check (#3983) --- .../Systems/SharedTransformSystem.Component.cs | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/Robust.Shared/GameObjects/Systems/SharedTransformSystem.Component.cs b/Robust.Shared/GameObjects/Systems/SharedTransformSystem.Component.cs index 63a46f922..1caa09209 100644 --- a/Robust.Shared/GameObjects/Systems/SharedTransformSystem.Component.cs +++ b/Robust.Shared/GameObjects/Systems/SharedTransformSystem.Component.cs @@ -472,6 +472,21 @@ public abstract partial class SharedTransformSystem QueueDel(uid); throw new InvalidOperationException($"Attempted to re-parent to a terminating object. Entity: {ToPrettyString(uid)}, new parent: {ToPrettyString(value.EntityId)}"); } + + // TODO maybe don't wrap this in DEBUG check once querying components is faster. + #if DEBUG + if (xform.MapUid == newParent.MapUid) + { + var recursiveXform = newParent; + while (recursiveXform.ParentUid.IsValid()) + { + if (recursiveXform.ParentUid == uid) + throw new InvalidOperationException($"Attempted to parent an entity to one of its descendants! {ToPrettyString(uid)}"); + + recursiveXform = xformQuery.GetComponent(recursiveXform.ParentUid); + } + } + #endif } if (xform._parent.IsValid())