Give more context when crashing during .png sheet loading.
This commit is contained in:
committed by
atlimit8
parent
2abd137494
commit
c131728aa4
@@ -96,13 +96,18 @@ namespace OpenRA.Mods.Common.SpriteLoaders
|
|||||||
{
|
{
|
||||||
regions = new List<Rectangle>();
|
regions = new List<Rectangle>();
|
||||||
offsets = new List<float2>();
|
offsets = new List<float2>();
|
||||||
|
var pngRectangle = new Rectangle(0, 0, png.Width, png.Height);
|
||||||
|
|
||||||
string frame;
|
string frame;
|
||||||
for (var i = 0; png.EmbeddedData.TryGetValue("Frame[" + i + "]", out frame); i++)
|
for (var i = 0; png.EmbeddedData.TryGetValue("Frame[" + i + "]", out frame); i++)
|
||||||
{
|
{
|
||||||
// Format: x,y,width,height;offsetX,offsetY
|
// Format: x,y,width,height;offsetX,offsetY
|
||||||
var coords = frame.Split(';');
|
var coords = frame.Split(';');
|
||||||
regions.Add(FieldLoader.GetValue<Rectangle>("Region", coords[0]));
|
var region = FieldLoader.GetValue<Rectangle>("Region", coords[0]);
|
||||||
|
if (!pngRectangle.Contains(region))
|
||||||
|
throw new InvalidDataException("Invalid frame regions {0} defined.".F(region));
|
||||||
|
|
||||||
|
regions.Add(region);
|
||||||
offsets.Add(FieldLoader.GetValue<float2>("Offset", coords[1]));
|
offsets.Add(FieldLoader.GetValue<float2>("Offset", coords[1]));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -141,6 +146,10 @@ namespace OpenRA.Mods.Common.SpriteLoaders
|
|||||||
|
|
||||||
var framesPerRow = png.Width / frameSize.Width;
|
var framesPerRow = png.Width / frameSize.Width;
|
||||||
|
|
||||||
|
var rows = (frameAmount + framesPerRow - 1) / framesPerRow;
|
||||||
|
if (png.Width < frameSize.Width * frameAmount / rows || png.Height < frameSize.Height * rows)
|
||||||
|
throw new InvalidDataException("Invalid frame size {0} and frame amount {1} defined.".F(frameSize, frameAmount));
|
||||||
|
|
||||||
regions = new List<Rectangle>();
|
regions = new List<Rectangle>();
|
||||||
offsets = new List<float2>();
|
offsets = new List<float2>();
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user