Revert "entity creation crash fixes"

This reverts commit 603c252c48.
This commit is contained in:
Kara D
2021-11-10 12:09:31 -07:00
parent 603c252c48
commit 0972601a43
2 changed files with 14 additions and 22 deletions

View File

@@ -69,29 +69,21 @@ namespace Robust.Server.GameObjects
if (!string.IsNullOrWhiteSpace(prototypeName))
{
if (PrototypeManager.TryIndex<EntityPrototype>(prototypeName, out var prototype))
{
var prototype = PrototypeManager.Index<EntityPrototype>(prototypeName);
// At this point in time, all data configure on the entity *should* be purely from the prototype.
// As such, we can reset the modified ticks to Zero,
// which indicates "not different from client's own deserialization".
// So the initial data for the component or even the creation doesn't have to be sent over the wire.
foreach (var (netId, component) in GetNetComponents(entity.Uid))
{
// Make sure to ONLY get components that are defined in the prototype.
// Others could be instantiated directly by AddComponent (e.g. ContainerManager).
// And those aren't guaranteed to exist on the client, so don't clear them.
if (prototype.Components.ContainsKey(component.Name)) ((Component) component).ClearTicks();
}
}
else
// At this point in time, all data configure on the entity *should* be purely from the prototype.
// As such, we can reset the modified ticks to Zero,
// which indicates "not different from client's own deserialization".
// So the initial data for the component or even the creation doesn't have to be sent over the wire.
foreach (var (netId, component) in GetNetComponents(entity.Uid))
{
Logger.Error($"Invalid prototypeId '{prototypeName}' passed to {nameof(CreateEntity)}.");
// Make sure to ONLY get components that are defined in the prototype.
// Others could be instantiated directly by AddComponent (e.g. ContainerManager).
// And those aren't guaranteed to exist on the client, so don't clear them.
if (prototype.Components.ContainsKey(component.Name)) ((Component) component).ClearTicks();
}
}
return entity;
}

View File

@@ -3,7 +3,6 @@ using System.Collections.Generic;
using System.Diagnostics.CodeAnalysis;
using System.Linq;
using Prometheus;
using Robust.Shared.Log;
using Robust.Shared.Map;
using Robust.Shared.Prototypes;
using Robust.Shared.Timing;
@@ -350,9 +349,10 @@ namespace Robust.Shared.GameObjects
private protected Entity AllocEntity(string? prototypeName, EntityUid? uid = null)
{
EntityPrototype? prototype = null;
if(!string.IsNullOrWhiteSpace(prototypeName) && !PrototypeManager.TryIndex<EntityPrototype>(prototypeName, out prototype))
if (!string.IsNullOrWhiteSpace(prototypeName))
{
Logger.Error($"Invalid prototypeId '{prototypeName}' passed to {nameof(AllocEntity)}.");
// If the prototype doesn't exist then we throw BEFORE we allocate the entity.
prototype = PrototypeManager.Index<EntityPrototype>(prototypeName);
}
var entity = AllocEntity(uid);
@@ -405,7 +405,7 @@ namespace Robust.Shared.GameObjects
/// </summary>
private protected virtual Entity CreateEntity(string? prototypeName, EntityUid? uid = null)
{
if (!string.IsNullOrWhiteSpace(prototypeName))
if (prototypeName == null)
return AllocEntity(uid);
var entity = AllocEntity(prototypeName, uid);