Skip to content

Commit

Permalink
Fix TimedDespawnComponent causing a crash if spawning another entity …
Browse files Browse the repository at this point in the history
…with TimedDespawnComponent (#5345)
  • Loading branch information
EmoGarbage404 authored Aug 10, 2024
1 parent b503390 commit 99e4910
Showing 1 changed file with 13 additions and 4 deletions.
17 changes: 13 additions & 4 deletions Robust.Shared/Spawners/SharedTimedDespawnSystem.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
using Robust.Shared.Audio;
using System.Collections.Generic;
using Robust.Shared.GameObjects;
using Robust.Shared.IoC;
using Robust.Shared.Timing;
Expand All @@ -9,6 +9,8 @@ public abstract class SharedTimedDespawnSystem : EntitySystem
{
[Dependency] private readonly IGameTiming _timing = default!;

private readonly HashSet<EntityUid> _queuedDespawnEntities = new();

public override void Initialize()
{
base.Initialize();
Expand All @@ -24,6 +26,8 @@ public override void Update(float frameTime)
if (!_timing.IsFirstTimePredicted)
return;

_queuedDespawnEntities.Clear();

var query = EntityQueryEnumerator<TimedDespawnComponent>();

while (query.MoveNext(out var uid, out var comp))
Expand All @@ -35,11 +39,16 @@ public override void Update(float frameTime)

if (comp.Lifetime <= 0)
{
var ev = new TimedDespawnEvent();
RaiseLocalEvent(uid, ref ev);
QueueDel(uid);
_queuedDespawnEntities.Add(uid);
}
}

foreach (var queued in _queuedDespawnEntities)
{
var ev = new TimedDespawnEvent();
RaiseLocalEvent(queued, ref ev);
QueueDel(queued);
}
}

protected abstract bool CanDelete(EntityUid uid);
Expand Down

0 comments on commit 99e4910

Please sign in to comment.