Fixed IndexOutOfRange exceptions when cloning items with requiredItems that aren't present in the xml, + some more exception handling & error logging
This commit is contained in:
@@ -495,14 +495,24 @@ namespace Barotrauma
|
||||
if (!property.Value.Attributes.OfType<Editable>().Any()) continue;
|
||||
clone.properties[property.Key].TrySetValue(property.Value.GetValue());
|
||||
}
|
||||
for (int i = 0; i < components.Count; i++)
|
||||
|
||||
if (components.Count != clone.components.Count)
|
||||
{
|
||||
string errorMsg = "Error while cloning item \"" + Name + "\" - clone does not have the same number of components. ";
|
||||
errorMsg += "Original components: " + string.Join(", ", components.Select(c => c.GetType().ToString()));
|
||||
errorMsg += ", cloned components: " + string.Join(", ", clone.components.Select(c => c.GetType().ToString()));
|
||||
DebugConsole.ThrowError(errorMsg);
|
||||
GameAnalyticsManager.AddErrorEventOnce("Item.Clone:" + Name, GameAnalyticsSDK.Net.EGAErrorSeverity.Error, errorMsg);
|
||||
}
|
||||
|
||||
for (int i = 0; i < components.Count && i < clone.components.Count; i++)
|
||||
{
|
||||
foreach (KeyValuePair<string, SerializableProperty> property in components[i].properties)
|
||||
{
|
||||
if (!property.Value.Attributes.OfType<Editable>().Any()) continue;
|
||||
clone.components[i].properties[property.Key].TrySetValue(property.Value.GetValue());
|
||||
}
|
||||
for (int j = 0; j < components[i].requiredItems.Count; j++)
|
||||
for (int j = 0; j < components[i].requiredItems.Count && i < clone.components[i].requiredItems.Count; j++)
|
||||
{
|
||||
clone.components[i].requiredItems[j].JoinedNames = components[i].requiredItems[j].JoinedNames;
|
||||
}
|
||||
|
||||
@@ -171,7 +171,19 @@ namespace Barotrauma
|
||||
foreach (MapEntity e in entitiesToClone)
|
||||
{
|
||||
Debug.Assert(e != null);
|
||||
clones.Add(e.Clone());
|
||||
try
|
||||
{
|
||||
clones.Add(e.Clone());
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
DebugConsole.ThrowError("Cloning entity \"" + e.Name + "\" failed.", ex);
|
||||
GameAnalyticsManager.AddErrorEventOnce(
|
||||
"MapEntity.Clone:" + e.Name,
|
||||
GameAnalyticsSDK.Net.EGAErrorSeverity.Error,
|
||||
"Cloning entity \"" + e.Name + "\" failed (" + ex.Message + ").\n" + ex.StackTrace);
|
||||
return clones;
|
||||
}
|
||||
Debug.Assert(clones.Last() != null);
|
||||
}
|
||||
|
||||
|
||||
@@ -170,7 +170,7 @@ namespace Barotrauma
|
||||
{
|
||||
get
|
||||
{
|
||||
return subBody.Borders;
|
||||
return subBody == null ? Rectangle.Empty : subBody.Borders;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user