Avoid null vectors when making colors valid
If the picked color and a forbidden color are identical (like if they both picked the same palette color and in the special case when a picked color is outside of the allowed range and the method returns the picked color as the forbidden color), the vector between them is zero and the maths for adjusting the color fails by hitting the iteration limit. This changes the zero vector to the smallest possible vector in order to avoid the issue. This can result in some seriously close adjustments in the case of picking identical palette colors, which might be undesirable compared to picking a new palette color.
This commit is contained in:
@@ -137,7 +137,14 @@ namespace OpenRA.Mods.Common
|
||||
// Reduce vector by it's biggest value (more calculations, but more accuracy too)
|
||||
var vectorMax = vector.Max(vv => Math.Abs(vv));
|
||||
if (vectorMax == 0)
|
||||
vectorMax = 1; // Avoid division by 0
|
||||
{
|
||||
vectorMax = 1; // Avoid division by 0
|
||||
|
||||
// Create a tiny vector to make the while loop maths work
|
||||
vector[0] = 1;
|
||||
vector[1] = 1;
|
||||
vector[2] = 1;
|
||||
}
|
||||
|
||||
vector[0] /= vectorMax;
|
||||
vector[1] /= vectorMax;
|
||||
|
||||
Reference in New Issue
Block a user