changeset 221:78f7456f6419

Re #228: Crash with missing abilityID * Quick fix to check if an ability ID doesn't match an ability and throw a standard error if it isn't found TODO: * Need to check why it isn't handled by the attribute type (IDREF) * Need to test it works! Problem shouldn't occur for <notes> because it is just a block of text and isn't referenced anywhere
author IBBoard <dev@ibboard.co.uk>
date Mon, 07 Dec 2009 19:40:12 +0000
parents 7441a62c5a06
children 2f9ad5385707
files api/Factories/Xml/WarFoundryXmlRaceFactory.cs
diffstat 1 files changed, 8 insertions(+), 1 deletions(-) [+]
line wrap: on
line diff
--- a/api/Factories/Xml/WarFoundryXmlRaceFactory.cs	Mon Dec 07 19:34:51 2009 +0000
+++ b/api/Factories/Xml/WarFoundryXmlRaceFactory.cs	Mon Dec 07 19:40:12 2009 +0000
@@ -330,8 +330,15 @@
 			foreach (XmlElement ability in WarFoundryXmlFactoryUtils.SelectNodes(elem, "race:unitAbilities/race:unitAbility"))
 			{
 				string id = ability.GetAttribute("abilityID");
+				Ability ability = type.Race.GetAbility(id);
+				
+				if (ability == null)
+				{
+					throw new InvalidFileException("Ability for "+type.Name+ " with ID "+id+ " did not exist in race definition");
+				}
+				
 				bool required = XmlTools.GetBoolValueFromAttribute(ability, "required");
-				type.AddAbility(type.Race.GetAbility(id), required);
+				type.AddAbility(ability, required);
 			}
 		}