mirror of
https://github.com/space-wizards/RobustToolbox.git
synced 2026-02-14 19:29:36 +01:00
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 <pieterjan.briers+git@gmail.com>
This commit is contained in:
committed by
GitHub
parent
0e54fa7329
commit
5e160e26ee
@@ -838,18 +838,16 @@ namespace Robust.Shared.GameObjects
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
public bool EnsureComponent<T>(ref Entity<T?> 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<T>(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<T>(entity);
|
||||
return false;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user