From 5e160e26ee2b383da97426ae89e5df12a3022ee3 Mon Sep 17 00:00:00 2001 From: Princess Cheeseballs <66055347+Princess-Cheeseballs@users.noreply.github.com> Date: Sat, 31 Jan 2026 06:59:39 -0800 Subject: [PATCH] Prevent a potential EnsureComp exception. (#6405) Fix potential EnsureComponent collision Co-authored-by: Princess Cheeseballs <66055347+Pronana@users.noreply.github.com> Co-authored-by: PJB3005 --- .../GameObjects/EntityManager.Components.cs | 18 ++++++++---------- 1 file changed, 8 insertions(+), 10 deletions(-) diff --git a/Robust.Shared/GameObjects/EntityManager.Components.cs b/Robust.Shared/GameObjects/EntityManager.Components.cs index 09dd5cdf5..a4b2d4cef 100644 --- a/Robust.Shared/GameObjects/EntityManager.Components.cs +++ b/Robust.Shared/GameObjects/EntityManager.Components.cs @@ -838,18 +838,16 @@ namespace Robust.Shared.GameObjects [MethodImpl(MethodImplOptions.AggressiveInlining)] public bool EnsureComponent(ref Entity entity) where T : IComponent, new() { - if (entity.Comp != null) - { - // Check for deferred component removal. - if (entity.Comp.LifeStage <= ComponentLifeStage.Running) - { - DebugTools.AssertOwner(entity, entity.Comp); - return true; - } + if (entity.Comp == null) + return EnsureComponent(entity.Owner, out entity.Comp); - RemoveComponent(entity, entity.Comp); - } + DebugTools.AssertOwner(entity, entity.Comp); + // Check for deferred component removal. + if (entity.Comp.LifeStage <= ComponentLifeStage.Running) + return true; + + RemoveComponent(entity, entity.Comp); entity.Comp = AddComponent(entity); return false; }