From e024b735533842e655eeb3ee845dbcb4bfef5f51 Mon Sep 17 00:00:00 2001 From: hikerstk Date: Wed, 6 Nov 2013 06:21:32 +0000 Subject: [PATCH] Avoid potential division by zero (which might cause crashes). git-svn-id: svn+ssh://svn.code.sf.net/p/supertuxkart/code/main/trunk@14393 178a84e3-b1eb-0310-8ba1-8eac791a3b58 --- src/items/rubber_ball.cpp | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/src/items/rubber_ball.cpp b/src/items/rubber_ball.cpp index fc08f80ae..5931f20fd 100644 --- a/src/items/rubber_ball.cpp +++ b/src/items/rubber_ball.cpp @@ -426,7 +426,11 @@ void RubberBall::moveTowardsTarget(Vec3 *next_xyz, float dt) // at it directly, stop interpolating, instead fly straight // towards it. Vec3 diff = m_target->getXYZ()-getXYZ(); - *next_xyz = getXYZ() + (dt*m_speed/diff.length())*diff; + // Avoid potential division by zero + if(diff.length2()==0) + *next_xyz = getXYZ(); + else + *next_xyz = getXYZ() + (dt*m_speed/diff.length())*diff; Vec3 old_vec = getXYZ()-m_previous_xyz; Vec3 new_vec = *next_xyz - getXYZ();