[Orxonox-commit 5971] r10630 - code/trunk/src/libraries/util

landauf at orxonox.net landauf at orxonox.net
Sat Oct 10 18:36:49 CEST 2015


Author: landauf
Date: 2015-10-10 18:36:49 +0200 (Sat, 10 Oct 2015)
New Revision: 10630

Modified:
   code/trunk/src/libraries/util/Math.cc
Log:
avoid division by zero errors (happened e.g. if 'myposition' and 'targetposition' were equal)

Modified: code/trunk/src/libraries/util/Math.cc
===================================================================
--- code/trunk/src/libraries/util/Math.cc	2015-10-10 14:34:26 UTC (rev 10629)
+++ code/trunk/src/libraries/util/Math.cc	2015-10-10 16:36:49 UTC (rev 10630)
@@ -357,9 +357,14 @@
 
         float discriminant = b*b - 4*a*c;
         if (discriminant < 0)
-            return orxonox::Vector3::ZERO;
+            return orxonox::Vector3::ZERO; // solution is undefined (e.g. target faster than projectile)
 
+        if (a == 0.0f)
+            return orxonox::Vector3::ZERO; // avoid division by zero
         float solution = (-b + sqrt(discriminant)) / (2 * a);
+
+        if (solution == 0.0f)
+            return orxonox::Vector3::ZERO; // avoid division by zero
         float time = 1.0f / solution;
 
         return (targetposition + targetvelocity * time);




More information about the Orxonox-commit mailing list