Throw specific cursor sequence errors

instead of dividing by zero because length is 0.
This commit is contained in:
Matthias Mailänder
2022-12-11 13:24:57 +01:00
committed by abcdefg30
parent 6d438a9d61
commit 56ff98a2a3

View File

@@ -31,7 +31,8 @@ namespace OpenRA.Graphics
Palette = palette; Palette = palette;
Name = name; Name = name;
Frames = cache[cursorSrc].Skip(Start).ToArray(); var cursorSprites = cache[cursorSrc];
Frames = cursorSprites.Skip(Start).ToArray();
if ((d.ContainsKey("Length") && d["Length"].Value == "*") || (d.ContainsKey("End") && d["End"].Value == "*")) if ((d.ContainsKey("Length") && d["Length"].Value == "*") || (d.ContainsKey("End") && d["End"].Value == "*"))
Length = Frames.Length; Length = Frames.Length;
@@ -44,6 +45,12 @@ namespace OpenRA.Graphics
Frames = Frames.Take(Length).ToArray(); Frames = Frames.Take(Length).ToArray();
if (Start > cursorSprites.Length)
throw new YamlException($"Cursor {name}: {nameof(Start)} is greater than the length of the sprite sequence.");
if (Length > cursorSprites.Length)
throw new YamlException($"Cursor {name}: {nameof(Length)} is greater than the length of the sprite sequence.");
if (d.ContainsKey("X")) if (d.ContainsKey("X"))
{ {
Exts.TryParseIntegerInvariant(d["X"].Value, out var x); Exts.TryParseIntegerInvariant(d["X"].Value, out var x);