Skip to content

Commit

Permalink
Verifying vector length before calling box2d RayCast method to preven…
Browse files Browse the repository at this point in the history
…t crashes
  • Loading branch information
andresan87 committed Jun 29, 2012
1 parent 0aa287b commit 457535b
Showing 1 changed file with 9 additions and 1 deletion.
10 changes: 9 additions & 1 deletion toolkit/Source/src/engine/Physics/ETHPhysicsSimulator.cpp
Expand Up @@ -233,7 +233,15 @@ ETHEntity* ETHPhysicsSimulator::GetClosestContact(const Vector2& a, const Vector
return 0;
ETHEntityDefaultChooser chooser;
ETHRayCastCallback rayCastCallback(a, b, &chooser);
m_world->RayCast(&rayCastCallback, rayCastCallback.GetScaledA(), rayCastCallback.GetScaledB());
const b2Vec2& p1 = rayCastCallback.GetScaledA();
const b2Vec2& p2 = rayCastCallback.GetScaledB();

// verify it again since values have been scaled and this
// is an assert test in the box2D code
if (b2Vec2(p2 - p1).LengthSquared() <= 0.0f)
return 0;

m_world->RayCast(&rayCastCallback, p1, p2);
return rayCastCallback.GetClosestContact(point, normal);
}

Expand Down

0 comments on commit 457535b

Please sign in to comment.