From 41ab08ee4716b5e2e7da10bf52b4ce5c3ed49321 Mon Sep 17 00:00:00 2001 From: Christoph Oelckers Date: Mon, 3 Oct 2016 11:00:26 +0200 Subject: [PATCH] - fixed: TVector::Resized needs to consider that the input vector has a length of 0. In this case just performing the normal calculations results in an invalid vector. --- src/vectors.h | 24 ++++++++++++++++++------ 1 file changed, 18 insertions(+), 6 deletions(-) diff --git a/src/vectors.h b/src/vectors.h index 00a65df50..1852609f2 100644 --- a/src/vectors.h +++ b/src/vectors.h @@ -556,17 +556,29 @@ struct TVector3 // Resizes this vector to be the specified length (if it is not 0) TVector3 &MakeResize(double len) { - double scale = len / Length(); - X = vec_t(X * scale); - Y = vec_t(Y * scale); - Z = vec_t(Z * scale); + double vlen = Length(); + if (vlen != 0.) + { + double scale = len / vlen; + X = vec_t(X * scale); + Y = vec_t(Y * scale); + Z = vec_t(Z * scale); + } return *this; } TVector3 Resized(double len) { - double scale = len / Length(); - return{ vec_t(X * scale), vec_t(Y * scale), vec_t(Z * scale) }; + double vlen = Length(); + if (vlen != 0.) + { + double scale = len / vlen; + return{ vec_t(X * scale), vec_t(Y * scale), vec_t(Z * scale) }; + } + else + { + return *this; + } } // Dot product