From ed5c4b44d442ad9b5e283a3f53efda365248b1c1 Mon Sep 17 00:00:00 2001 From: Ellpeck Date: Tue, 30 Jan 2024 20:34:36 +0100 Subject: [PATCH] fixed empty nine patch regions stalling when using tile mode closes #17 --- MLEM/Textures/NinePatch.cs | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/MLEM/Textures/NinePatch.cs b/MLEM/Textures/NinePatch.cs index 1a3481c..827af62 100644 --- a/MLEM/Textures/NinePatch.cs +++ b/MLEM/Textures/NinePatch.cs @@ -158,11 +158,13 @@ namespace MLEM.Textures { case NinePatchMode.Tile: var width = src.Width * patchScale; var height = src.Height * patchScale; - for (var x = 0F; x < rect.Width; x += width) { - for (var y = 0F; y < rect.Height; y += height) { - var size = new Vector2(Math.Min(rect.Width - x, width), Math.Min(rect.Height - y, height)); - var srcSize = (size / patchScale).CeilCopy().ToPoint(); - batch.Draw(texture.Region.Texture, new RectangleF(rect.Location + new Vector2(x, y), size), new Rectangle(src.X, src.Y, srcSize.X, srcSize.Y), color, rotation, origin, effects, layerDepth); + if (width > 0 && height > 0) { + for (var x = 0F; x < rect.Width; x += width) { + for (var y = 0F; y < rect.Height; y += height) { + var size = new Vector2(Math.Min(rect.Width - x, width), Math.Min(rect.Height - y, height)); + var srcSize = (size / patchScale).CeilCopy().ToPoint(); + batch.Draw(texture.Region.Texture, new RectangleF(rect.Location + new Vector2(x, y), size), new Rectangle(src.X, src.Y, srcSize.X, srcSize.Y), color, rotation, origin, effects, layerDepth); + } } } break;