Add more PVS logs (#4730)

This commit is contained in:
Leon Friedrich
2023-12-17 20:36:48 -05:00
committed by GitHub
parent 1009dd3ea0
commit 005c2e784a
6 changed files with 28 additions and 11 deletions

View File

@@ -14,7 +14,16 @@ internal sealed partial class PvsSystem
{
ref var data = ref CollectionsMarshal.GetValueRefOrAddDefault(entityData, entity, out var exists);
if (!exists)
data = new(GetEntityData(entity));
{
if (TryGetEntityData(entity, out var uid, out var meta))
{
data = new((uid.Value, meta));
}
else
{
Log.Error($"Attempted to add deleted entity. NetUid: {entity}");
}
}
DebugTools.AssertEqual(data.Entity.Comp.NetEntity, entity);
return ref data;
}

View File

@@ -29,7 +29,8 @@ internal sealed partial class PvsSystem
DebugTools.AssertNotEqual(data.LastSent, toTick);
DebugTools.AssertEqual(toTick, _gameTiming.CurTick);
if (meta.EntityLifeStage >= EntityLifeStage.Terminating)
// ReSharper disable once ConditionIsAlwaysTrueOrFalse
if (meta == null || meta.EntityLifeStage >= EntityLifeStage.Terminating)
{
var rep = new EntityStringRepresentation(data.Entity);
Log.Error($"Attempted to add a deleted entity to PVS send set: '{rep}'. Deletion queued: {EntityManager.IsQueuedForDeletion(data.Entity)}. Trace:\n{Environment.StackTrace}");
@@ -135,7 +136,6 @@ internal sealed partial class PvsSystem
var (entered, budgetExceeded) = GetPvsEntryData(ref data, fromTick, toTick,
ref newEntityCount, ref enteredEntityCount, newEntityBudget, enteredEntityBudget);
if (budgetExceeded)
{
// should be false for the majority of entities
@@ -150,7 +150,12 @@ internal sealed partial class PvsSystem
AddToSendList(currentNodeIndex, ref data, toSend, fromTick, toTick, entered, ref dirtyEntityCount);
}
var node = tree[currentNodeIndex];
if (!tree.TryGet(currentNodeIndex, out var node))
{
Log.Error($"tree is missing the current node! Node: {currentNodeIndex}");
continue;
}
if (node.Children == null)
continue;

View File

@@ -34,6 +34,8 @@ public sealed class RobustTree<T> where T : notnull
public TreeNode this[T index] => _nodeIndex[index];
public bool TryGet(T index, out TreeNode node) => _nodeIndex.TryGetValue(index, out node);
public void Remove(T value, bool mend = false)
{
if (!_nodeIndex.TryGetValue(value, out var node))

View File

@@ -254,7 +254,8 @@ Oldest acked clients: {string.Join(", ", players)}
}
catch (Exception e) // Catch EVERY exception
{
_logger.Log(LogLevel.Error, e, "Caught exception while generating mail.");
var source = i >= 0 ? players[i].ToString() : "replays";
_logger.Log(LogLevel.Error, e, $"Caught exception while generating mail for {source}.");
}
return resource;
}

View File

@@ -736,7 +736,7 @@ namespace Robust.Shared.GameObjects
public virtual EntityStringRepresentation ToPrettyString(EntityUid uid, MetaDataComponent? metadata = null)
{
if (!MetaQuery.Resolve(uid, ref metadata, false))
return new EntityStringRepresentation(uid, true);
return new EntityStringRepresentation(uid, default, true);
return new EntityStringRepresentation(uid, metadata);
}
@@ -752,7 +752,7 @@ namespace Robust.Shared.GameObjects
public EntityStringRepresentation ToPrettyString(NetEntity netEntity)
{
if (!TryGetEntityData(netEntity, out var uid, out var meta))
return new EntityStringRepresentation(EntityUid.Invalid, true);
return new EntityStringRepresentation(EntityUid.Invalid, netEntity, true);
return ToPrettyString(uid.Value, meta);
}

View File

@@ -17,23 +17,23 @@ namespace Robust.Shared.GameObjects;
/// <param name="Prototype">The prototype identifier of the entity, if any.</param>
/// <param name="Session">The session attached to the entity, if any.</param>
public readonly record struct EntityStringRepresentation
(EntityUid Uid, bool Deleted, string? Name = null, string? Prototype = null, ICommonSession? Session = null) : IFormattable
(EntityUid Uid, NetEntity Nuid, bool Deleted, string? Name = null, string? Prototype = null, ICommonSession? Session = null) : IFormattable
{
public EntityStringRepresentation(Entity<MetaDataComponent> entity) : this(entity.Owner, entity.Comp)
{
}
public EntityStringRepresentation(EntityUid uid, MetaDataComponent meta)
: this(uid, meta.EntityDeleted, meta.EntityName, meta.EntityPrototype?.ID)
: this(uid, meta.NetEntity, meta.EntityDeleted, meta.EntityName, meta.EntityPrototype?.ID)
{
}
public override string ToString()
{
if (Deleted && Name == null)
return $"{Uid}D";
return $"{Uid}/n{Nuid}D";
return $"{Name} ({Uid}{(Prototype != null ? $", {Prototype}" : "")}{(Session != null ? $", {Session.Name}" : "")}){(Deleted ? "D" : "")}";
return $"{Name} ({Uid}/n{Nuid}{(Prototype != null ? $", {Prototype}" : "")}{(Session != null ? $", {Session.Name}" : "")}){(Deleted ? "D" : "")}";
}
public string ToString(string? format, IFormatProvider? formatProvider)