From 2747fadd9624357db4f34502106bc39ad17b68e9 Mon Sep 17 00:00:00 2001 From: Chris Forbes Date: Sat, 3 Dec 2011 19:23:14 +1300 Subject: [PATCH] #657 give a useful error message when a sequence references frames outside the range that actually exist --- OpenRA.Game/Graphics/Sequence.cs | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/OpenRA.Game/Graphics/Sequence.cs b/OpenRA.Game/Graphics/Sequence.cs index 5e5c6e77ed..5b114e9d07 100644 --- a/OpenRA.Game/Graphics/Sequence.cs +++ b/OpenRA.Game/Graphics/Sequence.cs @@ -8,9 +8,10 @@ */ #endregion +using System; using System.Xml; -using OpenRA.FileFormats; using System.Collections.Generic; +using OpenRA.FileFormats; namespace OpenRA.Graphics { @@ -33,7 +34,7 @@ namespace OpenRA.Graphics Name = name; var d = info.NodesDict; - sprites = Game.modData.SpriteLoader.LoadAllSprites(string.IsNullOrEmpty(srcOverride) ? unit : srcOverride ); + sprites = Game.modData.SpriteLoader.LoadAllSprites(srcOverride ?? unit); start = int.Parse(d["Start"].Value); if (!d.ContainsKey("Length")) @@ -53,6 +54,12 @@ namespace OpenRA.Graphics tick = int.Parse(d["Tick"].Value); else tick = 40; + + if (start < 0 || start + facings * length > sprites.Length) + throw new InvalidOperationException( + "{6}: Sequence {0}.{1} uses frames [{2}..{3}] of SHP `{4}`, but only 0..{5} actually exist" + .F(unit, name, start, start + facings * length - 1, srcOverride ?? unit, sprites.Length - 1, + info.Nodes[0].Location)); } public MiniYaml Save()