Prevent radar crash when dealing with map height.

This commit is contained in:
RoosterDragon
2021-11-13 18:38:45 +00:00
committed by Matthias Mailänder
parent 539bb09d50
commit bcf4ff3b7c

View File

@@ -179,24 +179,35 @@ namespace OpenRA.Mods.Common.Widgets
// The minimap is drawn in cell space, so we need to
// unproject the bounds to find the extent of the map.
// TODO: This attempt to find the map bounds accounting for projected cell heights is bogus.
// When a map with height is involved, the bounds may not be optimal, this needs fixing.
var projectedLeft = map.Bounds.Left;
var projectedRight = map.Bounds.Right;
var projectedTop = map.Bounds.Top;
var projectedBottom = map.Bounds.Bottom;
var top = int.MaxValue;
var bottom = int.MinValue;
var left = map.Bounds.Left * cellWidth;
var right = map.Bounds.Right * cellWidth;
var left = projectedLeft * cellWidth;
var right = projectedRight * cellWidth;
for (var x = projectedLeft; x < projectedRight; x++)
{
// Unprojects check can fail and return an empty list.
// This happens when the map tile is outside the map projected space,
// e.g. if a tile on the bottom edge has a height > 0.
// Guard against this by using the map bounds as a fallback.
var allTop = map.Unproject(new PPos(x, projectedTop));
var allBottom = map.Unproject(new PPos(x, projectedBottom));
if (allTop.Count > 0)
top = Math.Min(top, allTop.MinBy(uv => uv.V).V);
else
top = map.Bounds.Top;
if (allBottom.Count > 0)
bottom = Math.Max(bottom, allBottom.MaxBy(uv => uv.V).V);
else
bottom = map.Bounds.Bottom;
}
var b = Rectangle.FromLTRB(left, top, right, bottom);