Fixed entity ID mismatches and desync kicks caused by gap creation/removal in Structure.SetDamage. Creating the gaps on damaged walls wasn't guaranteed to happen in the same order client-side as on the server, causing the IDs to get assigned mismatching IDs and in some cases also affecting the IDs of other types of entities (see #528).

Now the structure gaps simply don't have IDs. They're never accessed by ID so I don't think there's the need to make the creation/removal go through entityspawner.
This commit is contained in:
Joonas Rikkonen
2018-07-25 17:34:10 +03:00
parent 40f4e94613
commit b309b45246
3 changed files with 41 additions and 41 deletions
@@ -20,6 +20,8 @@ namespace Barotrauma
protected AITarget aiTarget;
private bool idFreed;
public virtual bool Removed
{
get;
@@ -52,7 +54,8 @@ namespace Barotrauma
DebugConsole.Log("The id of " + this + " is now " + value);
}
id = value;
id = value;
idFreed = false;
dictionary.Add(id, this);
}
}
@@ -199,21 +202,24 @@ namespace Barotrauma
dictionary.Clear();
}
public virtual void Remove()
/// <summary>
/// Removes the entity from the entity dictionary and frees up the ID it was using.
/// </summary>
public void FreeID()
{
DebugConsole.Log("Removing entity " + ToString() + " (" + ID + ") from entity dictionary.");
if (!dictionary.TryGetValue(ID, out Entity existingEntity))
{
DebugConsole.Log("Entity " + ToString() + " (" + ID + ") not present in entity dictionary.");
GameAnalyticsManager.AddErrorEventOnce(
"Entity.Remove:EntityNotFound" + ID,
"Entity.FreeID:EntityNotFound" + ID,
GameAnalyticsSDK.Net.EGAErrorSeverity.Error,
"Entity " + ToString() + " (" + ID + ") not present in entity dictionary.\n" + Environment.StackTrace);
}
else if (existingEntity != this)
{
DebugConsole.Log("Entity ID mismatch in entity dictionary. Entity " + existingEntity + " had the ID " + ID + " (expecting " + ToString() + ")");
GameAnalyticsManager.AddErrorEventOnce("Entity.Remove:EntityMismatch" + ID,
GameAnalyticsManager.AddErrorEventOnce("Entity.FreeID:EntityMismatch" + ID,
GameAnalyticsSDK.Net.EGAErrorSeverity.Error,
"Entity ID mismatch in entity dictionary. Entity " + existingEntity + " had the ID " + ID + " (expecting " + ToString() + ")");
@@ -224,6 +230,13 @@ namespace Barotrauma
}
dictionary.Remove(ID);
id = 0;
idFreed = true;
}
public virtual void Remove()
{
if (!idFreed) FreeID();
Removed = true;
}