mirror of
https://github.com/space-wizards/RobustToolbox.git
synced 2026-02-15 03:30:53 +01:00
Client entity deletion error tolerance (#3435)
This commit is contained in:
@@ -31,6 +31,17 @@ namespace Robust.Client.GameObjects
|
||||
|
||||
base.Initialize();
|
||||
}
|
||||
public override void Shutdown()
|
||||
{
|
||||
using var _ = _gameTiming.StartStateApplicationArea();
|
||||
base.Shutdown();
|
||||
}
|
||||
|
||||
public override void Cleanup()
|
||||
{
|
||||
using var _ = _gameTiming.StartStateApplicationArea();
|
||||
base.Cleanup();
|
||||
}
|
||||
|
||||
EntityUid IClientEntityManagerInternal.CreateEntity(string? prototypeName, EntityUid uid)
|
||||
{
|
||||
|
||||
@@ -1,8 +1,10 @@
|
||||
using System.Collections.Generic;
|
||||
using Robust.Client.Timing;
|
||||
using Robust.Shared.GameObjects;
|
||||
using Robust.Shared.IoC;
|
||||
using Robust.Shared.Log;
|
||||
using Robust.Shared.Utility;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
|
||||
namespace Robust.Client.GameStates;
|
||||
|
||||
@@ -23,6 +25,7 @@ internal sealed class ClientDirtySystem : EntitySystem
|
||||
public override void Initialize()
|
||||
{
|
||||
base.Initialize();
|
||||
SubscribeLocalEvent<EntityTerminatingEvent>(OnTerminate);
|
||||
EntityManager.EntityDirtied += OnEntityDirty;
|
||||
EntityManager.ComponentRemoved += OnCompRemoved;
|
||||
}
|
||||
@@ -35,6 +38,15 @@ internal sealed class ClientDirtySystem : EntitySystem
|
||||
Reset();
|
||||
}
|
||||
|
||||
private void OnTerminate(ref EntityTerminatingEvent ev)
|
||||
{
|
||||
if (!_timing.InPrediction || ev.Entity.IsClientSide())
|
||||
return;
|
||||
|
||||
// Client-side entity deletion is not supported and will cause errors.
|
||||
Logger.Error($"Predicting the deletion of a networked entity: {ToPrettyString(ev.Entity)}. Trace: {Environment.StackTrace}");
|
||||
}
|
||||
|
||||
private void OnCompRemoved(RemovedComponentEventArgs args)
|
||||
{
|
||||
if (args.Terminating)
|
||||
|
||||
@@ -249,7 +249,18 @@ namespace Robust.Client.GameStates
|
||||
}
|
||||
|
||||
if (PredictionNeedsResetting)
|
||||
ResetPredictedEntities();
|
||||
{
|
||||
try
|
||||
{
|
||||
ResetPredictedEntities();
|
||||
}
|
||||
catch
|
||||
{
|
||||
// avoid exception spam from repeatedly trying to reset the same entity.
|
||||
_entitySystemManager.GetEntitySystem<ClientDirtySystem>().Reset();
|
||||
throw;
|
||||
}
|
||||
}
|
||||
|
||||
// If we were waiting for a new state, we are now applying it.
|
||||
if (_processor.LastFullStateRequested.HasValue)
|
||||
@@ -463,7 +474,11 @@ namespace Robust.Client.GameStates
|
||||
|
||||
countReset += 1;
|
||||
|
||||
foreach (var (netId, comp) in _entityManager.GetNetComponents(entity))
|
||||
var netComps = _entityManager.GetNetComponentsOrNull(entity);
|
||||
if (netComps == null)
|
||||
return;
|
||||
|
||||
foreach (var (netId, comp) in netComps.Value)
|
||||
{
|
||||
DebugTools.AssertNotNull(netId);
|
||||
if (!comp.NetSyncEnabled)
|
||||
|
||||
@@ -952,6 +952,14 @@ namespace Robust.Shared.GameObjects
|
||||
return new NetComponentEnumerable(_netComponents[uid]);
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
public NetComponentEnumerable? GetNetComponentsOrNull(EntityUid uid)
|
||||
{
|
||||
return _netComponents.TryGetValue(uid, out var data)
|
||||
? new NetComponentEnumerable(data)
|
||||
: null;
|
||||
}
|
||||
|
||||
#region Join Functions
|
||||
|
||||
public AllEntityQueryEnumerator<TComp1> AllEntityQueryEnumerator<TComp1>()
|
||||
|
||||
@@ -113,7 +113,7 @@ namespace Robust.Shared.GameObjects
|
||||
Started = false;
|
||||
}
|
||||
|
||||
public void Cleanup()
|
||||
public virtual void Cleanup()
|
||||
{
|
||||
_componentFactory.ComponentAdded -= OnComponentAdded;
|
||||
_componentFactory.ComponentReferenceAdded -= OnComponentReferenceAdded;
|
||||
@@ -345,8 +345,8 @@ namespace Robust.Shared.GameObjects
|
||||
|
||||
try
|
||||
{
|
||||
var ev = new EntityTerminatingEvent();
|
||||
EventBus.RaiseLocalEvent(uid, ref ev);
|
||||
var ev = new EntityTerminatingEvent(uid);
|
||||
EventBus.RaiseLocalEvent(uid, ref ev, true);
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
|
||||
@@ -6,5 +6,11 @@ namespace Robust.Shared.GameObjects
|
||||
[ByRefEvent]
|
||||
public readonly struct EntityTerminatingEvent
|
||||
{
|
||||
public readonly EntityUid Entity;
|
||||
|
||||
public EntityTerminatingEvent(EntityUid entity)
|
||||
{
|
||||
Entity = entity;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -358,6 +358,14 @@ namespace Robust.Shared.GameObjects
|
||||
/// <returns>All components that have a network ID.</returns>
|
||||
NetComponentEnumerable GetNetComponents(EntityUid uid);
|
||||
|
||||
/// <summary>
|
||||
/// Returns ALL networked components on an entity, including deleted ones. Returns null if the entity does
|
||||
/// not exist.
|
||||
/// </summary>
|
||||
/// <param name="uid">Entity UID to look on.</param>
|
||||
/// <returns>All components that have a network ID.</returns>
|
||||
public NetComponentEnumerable? GetNetComponentsOrNull(EntityUid uid);
|
||||
|
||||
/// <summary>
|
||||
/// Gets a component state.
|
||||
/// </summary>
|
||||
|
||||
Reference in New Issue
Block a user