From 5899636e10f5d91745e137896f840ac577b9186a Mon Sep 17 00:00:00 2001 From: Taryn Hill Date: Thu, 1 Nov 2018 11:17:14 -0500 Subject: [PATCH] Fix SubCell indexing in Map.CenterOfSubCell and MapGrid.OffsetOfSubCell --- OpenRA.Game/Map/Map.cs | 2 +- OpenRA.Game/Map/MapGrid.cs | 6 +++++- 2 files changed, 6 insertions(+), 2 deletions(-) diff --git a/OpenRA.Game/Map/Map.cs b/OpenRA.Game/Map/Map.cs index afc43fd302..5a5ce00b1d 100644 --- a/OpenRA.Game/Map/Map.cs +++ b/OpenRA.Game/Map/Map.cs @@ -786,7 +786,7 @@ namespace OpenRA public WPos CenterOfSubCell(CPos cell, SubCell subCell) { var index = (int)subCell; - if (index >= 0 && index <= Grid.SubCellOffsets.Length) + if (index >= 0 && index < Grid.SubCellOffsets.Length) return CenterOfCell(cell) + Grid.SubCellOffsets[index]; return CenterOfCell(cell); } diff --git a/OpenRA.Game/Map/MapGrid.cs b/OpenRA.Game/Map/MapGrid.cs index a48cddc0ef..5e2c643c16 100644 --- a/OpenRA.Game/Map/MapGrid.cs +++ b/OpenRA.Game/Map/MapGrid.cs @@ -168,7 +168,11 @@ namespace OpenRA if (subCell == SubCell.Invalid || subCell == SubCell.Any) return WVec.Zero; - return SubCellOffsets[(int)subCell]; + var index = (int)subCell; + if (index >= 0 && index < SubCellOffsets.Length) + return SubCellOffsets[index]; + + return WVec.Zero; } } }