Make the legacy editor more robust against invalid templates.

This commit is contained in:
Paul Chote
2014-10-23 10:26:36 +13:00
parent 2b0042ca23
commit fda25a56ca
3 changed files with 12 additions and 2 deletions

View File

@@ -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);

View File

@@ -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++)

View File

@@ -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;
}
}
}