Prevent radar crash when dealing with map height.
This commit is contained in:
committed by
Matthias Mailänder
parent
539bb09d50
commit
bcf4ff3b7c
@@ -179,24 +179,35 @@ namespace OpenRA.Mods.Common.Widgets
|
|||||||
|
|
||||||
// The minimap is drawn in cell space, so we need to
|
// The minimap is drawn in cell space, so we need to
|
||||||
// unproject the bounds to find the extent of the map.
|
// 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 projectedLeft = map.Bounds.Left;
|
||||||
var projectedRight = map.Bounds.Right;
|
var projectedRight = map.Bounds.Right;
|
||||||
var projectedTop = map.Bounds.Top;
|
var projectedTop = map.Bounds.Top;
|
||||||
var projectedBottom = map.Bounds.Bottom;
|
var projectedBottom = map.Bounds.Bottom;
|
||||||
var top = int.MaxValue;
|
var top = int.MaxValue;
|
||||||
var bottom = int.MinValue;
|
var bottom = int.MinValue;
|
||||||
var left = map.Bounds.Left * cellWidth;
|
var left = projectedLeft * cellWidth;
|
||||||
var right = map.Bounds.Right * cellWidth;
|
var right = projectedRight * cellWidth;
|
||||||
|
|
||||||
for (var x = projectedLeft; x < projectedRight; x++)
|
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 allTop = map.Unproject(new PPos(x, projectedTop));
|
||||||
var allBottom = map.Unproject(new PPos(x, projectedBottom));
|
var allBottom = map.Unproject(new PPos(x, projectedBottom));
|
||||||
|
|
||||||
if (allTop.Count > 0)
|
if (allTop.Count > 0)
|
||||||
top = Math.Min(top, allTop.MinBy(uv => uv.V).V);
|
top = Math.Min(top, allTop.MinBy(uv => uv.V).V);
|
||||||
|
else
|
||||||
|
top = map.Bounds.Top;
|
||||||
|
|
||||||
if (allBottom.Count > 0)
|
if (allBottom.Count > 0)
|
||||||
bottom = Math.Max(bottom, allBottom.MaxBy(uv => uv.V).V);
|
bottom = Math.Max(bottom, allBottom.MaxBy(uv => uv.V).V);
|
||||||
|
else
|
||||||
|
bottom = map.Bounds.Bottom;
|
||||||
}
|
}
|
||||||
|
|
||||||
var b = Rectangle.FromLTRB(left, top, right, bottom);
|
var b = Rectangle.FromLTRB(left, top, right, bottom);
|
||||||
|
|||||||
Reference in New Issue
Block a user