From a2775a5c0f30490da4881a73f0c261189ee828d7 Mon Sep 17 00:00:00 2001 From: reaperrr Date: Mon, 13 May 2019 01:07:15 +0200 Subject: [PATCH] Fix DivideByZero crashes in Railgun projectile --- OpenRA.Mods.Common/Projectiles/Railgun.cs | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/OpenRA.Mods.Common/Projectiles/Railgun.cs b/OpenRA.Mods.Common/Projectiles/Railgun.cs index 0701cef67b..79032ba6fe 100644 --- a/OpenRA.Mods.Common/Projectiles/Railgun.cs +++ b/OpenRA.Mods.Common/Projectiles/Railgun.cs @@ -153,14 +153,17 @@ namespace OpenRA.Mods.Common.Projectiles // An easy vector to find which is perpendicular vector to forwardStep, with 0 Z component LeftVector = new WVec(ForwardStep.Y, -ForwardStep.X, 0); - LeftVector = 1024 * LeftVector / LeftVector.Length; + if (LeftVector.LengthSquared != 0) + LeftVector = 1024 * LeftVector / LeftVector.Length; // Vector that is pointing upwards from the ground UpVector = new WVec( -ForwardStep.X * ForwardStep.Z, -ForwardStep.Z * ForwardStep.Y, ForwardStep.X * ForwardStep.X + ForwardStep.Y * ForwardStep.Y); - UpVector = 1024 * UpVector / UpVector.Length; + + if (UpVector.LengthSquared != 0) + UpVector = 1024 * UpVector / UpVector.Length; //// LeftVector and UpVector are unit vectors of size 1024.