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
This commit is contained in:
hikerstk
2013-11-06 06:21:32 +00:00
parent d7319b766f
commit e024b73553

View File

@@ -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();