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:
Joonas Rikkonen
2018-09-10 12:06:39 +03:00
parent 2b3c0d103b
commit 57c9e5a731
3 changed files with 26 additions and 4 deletions
@@ -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;
}