Skip to content

Commit 2747fad

Browse files
committed
#657 give a useful error message when a sequence references frames outside the range that actually exist
1 parent 66c59ad commit 2747fad

File tree

1 file changed

+9
-2
lines changed

1 file changed

+9
-2
lines changed

OpenRA.Game/Graphics/Sequence.cs

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,9 +8,10 @@
88
*/
99
#endregion
1010

11+
using System;
1112
using System.Xml;
12-
using OpenRA.FileFormats;
1313
using System.Collections.Generic;
14+
using OpenRA.FileFormats;
1415

1516
namespace OpenRA.Graphics
1617
{
@@ -33,7 +34,7 @@ public Sequence(string unit, string name, MiniYaml info)
3334
Name = name;
3435
var d = info.NodesDict;
3536

36-
sprites = Game.modData.SpriteLoader.LoadAllSprites(string.IsNullOrEmpty(srcOverride) ? unit : srcOverride );
37+
sprites = Game.modData.SpriteLoader.LoadAllSprites(srcOverride ?? unit);
3738
start = int.Parse(d["Start"].Value);
3839

3940
if (!d.ContainsKey("Length"))
@@ -53,6 +54,12 @@ public Sequence(string unit, string name, MiniYaml info)
5354
tick = int.Parse(d["Tick"].Value);
5455
else
5556
tick = 40;
57+
58+
if (start < 0 || start + facings * length > sprites.Length)
59+
throw new InvalidOperationException(
60+
"{6}: Sequence {0}.{1} uses frames [{2}..{3}] of SHP `{4}`, but only 0..{5} actually exist"
61+
.F(unit, name, start, start + facings * length - 1, srcOverride ?? unit, sprites.Length - 1,
62+
info.Nodes[0].Location));
5663
}
5764

5865
public MiniYaml Save()

0 commit comments

Comments
 (0)