Don't crash with an unhelpful IndexOutOfRangeException.

This commit is contained in:
Paul Chote
2020-02-22 22:19:22 +01:00
committed by reaperrr
parent 31d98cc802
commit def65b10bd

View File

@@ -204,11 +204,24 @@ namespace OpenRA.Mods.Common.Graphics
"{0}: Sequence {1}.{2}: Length must be <= Frames.Length"
.F(info.Nodes[0].Location, sequence, animation));
if (Frames == null && (Start < 0 || Start + (Facings - 1) * Stride + Length > frameCount))
var end = Start + (Facings - 1) * Stride + Length - 1;
if (Frames != null)
{
foreach (var f in Frames)
if (f < 0 || f >= frameCount)
throw new InvalidOperationException(
"{5}: Sequence {0}.{1} defines a Frames override that references frame {4}, but only [{2}..{3}] actually exist"
.F(sequence, animation, Start, end, f, info.Nodes[0].Location));
if (Start < 0 || end >= Frames.Length)
throw new InvalidOperationException(
"{5}: Sequence {0}.{1} uses indices [{2}..{3}] of the Frames list, but only {4} frames are defined"
.F(sequence, animation, Start, end, Frames.Length, info.Nodes[0].Location));
}
else if (Start < 0 || end >= frameCount)
throw new InvalidOperationException(
"{5}: Sequence {0}.{1} uses frames [{2}..{3}], but only 0..{4} actually exist"
.F(sequence, animation, Start, Start + (Facings - 1) * Stride + Length - 1, frameCount - 1,
info.Nodes[0].Location));
.F(sequence, animation, Start, end, frameCount - 1, info.Nodes[0].Location));
if (ShadowStart >= 0 && ShadowStart + (Facings - 1) * Stride + Length > frameCount)
throw new InvalidOperationException(