From 2bd62ee09d68f6c365f2fca294e1a20685dbaffb Mon Sep 17 00:00:00 2001 From: Ellpeck Date: Fri, 6 Dec 2019 16:12:57 +0100 Subject: [PATCH] tiled sanity check --- MLEM.Extended/Tiled/TiledExtensions.cs | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/MLEM.Extended/Tiled/TiledExtensions.cs b/MLEM.Extended/Tiled/TiledExtensions.cs index f4915fc..edd08e1 100644 --- a/MLEM.Extended/Tiled/TiledExtensions.cs +++ b/MLEM.Extended/Tiled/TiledExtensions.cs @@ -58,7 +58,7 @@ namespace MLEM.Extended.Tiled { } public static TiledMapTile GetTile(this TiledMapTileLayer layer, int x, int y) { - return layer.GetTile((ushort) x, (ushort) y); + return !layer.IsInBounds(x, y) ? default : layer.GetTile((ushort) x, (ushort) y); } public static RectangleF GetArea(this TiledMapObject obj, TiledMap map, Vector2? position = null) { @@ -71,5 +71,9 @@ namespace MLEM.Extended.Tiled { return new Vector2(map.TileWidth, map.TileHeight); } + public static bool IsInBounds(this TiledMapTileLayer layer, int x, int y) { + return x >= 0 && y >= 0 && x < layer.Width && y < layer.Height; + } + } } \ No newline at end of file