Fix for System Overflow exception
caused by casting a greater than int.MaxValue decimal to int. Fix limits offset to int.MaxValue respectively int.MinValue.
This commit is contained in:
committed by
GitHub
parent
12af71e9d8
commit
333e8bae42
@@ -63,10 +63,11 @@ namespace OpenRA
|
||||
if (pitch.Angle == 0)
|
||||
return ret;
|
||||
|
||||
// Add an additional quadratic variation to height
|
||||
// Uses decimal to avoid integer overflow
|
||||
var offset = (int)((decimal)(b - a).Length * pitch.Tan() * mul * (div - mul) / (1024 * div * div));
|
||||
return new WPos(ret.X, ret.Y, ret.Z + offset);
|
||||
var tempoffset = (decimal)(b - a).Length * pitch.Tan() * mul * (div - mul) / (1024 * div * div);
|
||||
|
||||
var offset = (int)Math.Min(Math.Max((decimal)int.MinValue, tempoffset + (decimal)ret.Z), (decimal)int.MaxValue);
|
||||
|
||||
return new WPos(ret.X, ret.Y, offset);
|
||||
}
|
||||
|
||||
public override int GetHashCode() { return X.GetHashCode() ^ Y.GetHashCode() ^ Z.GetHashCode(); }
|
||||
|
||||
Reference in New Issue
Block a user