Use decimal instead of long for WPos offset

To remove overflow risk.
This commit is contained in:
reaperrr
2016-03-24 15:57:33 +01:00
parent fe23ac7f93
commit 33f26e05e1

View File

@@ -64,8 +64,8 @@ namespace OpenRA
return ret;
// Add an additional quadratic variation to height
// Attempts to avoid integer overflow by keeping the intermediate variables reasonably sized
var offset = (int)(((((((long)(b - a).Length * mul) / div) * (div - mul)) / div) * pitch.Tan()) / 1024);
// 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);
}