From def65b10bdf304004af7f17d0cb4ca31eb02a2b1 Mon Sep 17 00:00:00 2001 From: Paul Chote Date: Sat, 22 Feb 2020 22:19:22 +0100 Subject: [PATCH] Don't crash with an unhelpful IndexOutOfRangeException. --- .../Graphics/DefaultSpriteSequence.cs | 19 ++++++++++++++++--- 1 file changed, 16 insertions(+), 3 deletions(-) diff --git a/OpenRA.Mods.Common/Graphics/DefaultSpriteSequence.cs b/OpenRA.Mods.Common/Graphics/DefaultSpriteSequence.cs index dddb169fbc..2440922d75 100644 --- a/OpenRA.Mods.Common/Graphics/DefaultSpriteSequence.cs +++ b/OpenRA.Mods.Common/Graphics/DefaultSpriteSequence.cs @@ -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(