Commits

Bart van Strien committed a6d34d0

Fix love.physics.getDistance

  • Participants
  • Parent commits a54920f

Comments (0)

Files changed (1)

File src/modules/physics/box2d/Physics.cpp

 {
 	Fixture *fixtureA = luax_checktype<Fixture>(L, 1, "Fixture", PHYSICS_FIXTURE_T);
 	Fixture *fixtureB = luax_checktype<Fixture>(L, 2, "Fixture", PHYSICS_FIXTURE_T);
+	b2DistanceProxy pA, pB;
 	b2DistanceInput i;
-	b2DistanceProxy pA;
-	pA.Set(fixtureA->fixture->GetShape(), 0);
-	b2DistanceProxy pB;
-	pB.Set(fixtureB->fixture->GetShape(), 0);
-	i.proxyA = pA;
-	i.proxyB = pB;
-	i.transformA = fixtureA->fixture->GetBody()->GetTransform();
-	i.transformB = fixtureB->fixture->GetBody()->GetTransform();
-	i.useRadii = true;
 	b2DistanceOutput o;
 	b2SimplexCache c;
-	b2Distance(&o, &c, &i);
+	c.count = 0;
+	try
+	{
+		pA.Set(fixtureA->fixture->GetShape(), 0);
+		pB.Set(fixtureB->fixture->GetShape(), 0);
+		i.proxyA = pA;
+		i.proxyB = pB;
+		i.transformA = fixtureA->fixture->GetBody()->GetTransform();
+		i.transformB = fixtureB->fixture->GetBody()->GetTransform();
+		i.useRadii = true;
+		b2Distance(&o, &c, &i);
+	}
+	catch (love::Exception &e)
+	{
+		luaL_error(L, "%s", e.what());
+	}
 	lua_pushnumber(L, Physics::scaleUp(o.distance));
 	lua_pushnumber(L, Physics::scaleUp(o.pointA.x));
 	lua_pushnumber(L, Physics::scaleUp(o.pointA.y));