Browse Source

Stop Body:getWorldPoints from overflowing the lua stack

Bart van Strien 13 years ago
parent
commit
f6e9f4cac7
1 changed files with 7 additions and 2 deletions
  1. 7 2
      src/modules/physics/box2d/Body.cpp

+ 7 - 2
src/modules/physics/box2d/Body.cpp

@@ -316,9 +316,14 @@ namespace box2d
 
 		for (int i = 0;i<vcount;i++)
 		{
-			float x = (float)lua_tonumber(L, i*2+1);
-			float y = (float)lua_tonumber(L, i*2+2);
+			float x = (float)lua_tonumber(L, 1);
+			float y = (float)lua_tonumber(L, 2);
+			// Remove them, so we don't run out of stack space
+			lua_remove(L, 1);
+			lua_remove(L, 1);
+			// Time for scaling
 			b2Vec2 point = Physics::scaleUp(body->GetWorldPoint(Physics::scaleDown(b2Vec2(x, y))));
+			// And then we push the result
 			lua_pushnumber(L, point.x);
 			lua_pushnumber(L, point.y);
 		}