From fda25a56ca316e27165cec60344bac7273799794 Mon Sep 17 00:00:00 2001 From: Paul Chote Date: Thu, 23 Oct 2014 10:26:36 +1300 Subject: [PATCH] Make the legacy editor more robust against invalid templates. --- OpenRA.Editor/BrushTool.cs | 2 +- OpenRA.Editor/Surface.cs | 3 +++ OpenRA.Editor/TileSetRenderer.cs | 9 ++++++++- 3 files changed, 12 insertions(+), 2 deletions(-) diff --git a/OpenRA.Editor/BrushTool.cs b/OpenRA.Editor/BrushTool.cs index fb555190a4..8603a4a533 100644 --- a/OpenRA.Editor/BrushTool.cs +++ b/OpenRA.Editor/BrushTool.cs @@ -41,7 +41,7 @@ namespace OpenRA.Editor if (surface.Map.Contains(cell)) { var z = u + v * template.Size.X; - if (tile[z].Length > 0) + if (tile != null && tile[z].Length > 0) { var index = template.PickAny ? (byte)((u + pos.X) % 4 + ((v + pos.Y) % 4) * 4) : (byte)z; surface.Map.MapTiles.Value[cell] = new TerrainTile(brushTemplate.N, index); diff --git a/OpenRA.Editor/Surface.cs b/OpenRA.Editor/Surface.cs index e801a283aa..cfb22b35d8 100644 --- a/OpenRA.Editor/Surface.cs +++ b/OpenRA.Editor/Surface.cs @@ -275,6 +275,9 @@ namespace OpenRA.Editor var vj = v * ChunkSize + j; var tr = Map.MapTiles.Value[ui, vj]; var tile = TileSetRenderer.Data(tr.Type); + if (tile == null) + continue; + var index = (tr.Index < tile.Length) ? tr.Index : (byte)0; var rawImage = tile[index]; for (var x = 0; x < TileSetRenderer.TileSize; x++) diff --git a/OpenRA.Editor/TileSetRenderer.cs b/OpenRA.Editor/TileSetRenderer.cs index cc05aae7ce..caf8759a43 100644 --- a/OpenRA.Editor/TileSetRenderer.cs +++ b/OpenRA.Editor/TileSetRenderer.cs @@ -104,7 +104,14 @@ namespace OpenRA.Editor public byte[][] Data(ushort id) { - return templates[id]; + byte[][] template; + if (!templates.TryGetValue(id, out template)) + { + Console.WriteLine("warning: Unknown tile template {0}", id); + return null; + } + + return template; } } }