Browse Source

Fixed bug where destroyed objects in love.physics cause crash when collected.

rude 15 years ago
parent
commit
86ac10c3f6

+ 0 - 2
src/modules/physics/box2d/CircleShape.cpp

@@ -42,8 +42,6 @@ namespace box2d
 
 
 	CircleShape::~CircleShape()
 	CircleShape::~CircleShape()
 	{
 	{
-		body->body->DestroyShape(shape);
-		shape = 0;
 	}
 	}
 
 
 	float CircleShape::getRadius() const
 	float CircleShape::getRadius() const

+ 0 - 2
src/modules/physics/box2d/PolygonShape.cpp

@@ -42,8 +42,6 @@ namespace box2d
 
 
 	PolygonShape::~PolygonShape()
 	PolygonShape::~PolygonShape()
 	{
 	{
-		body->body->DestroyShape(shape);
-		shape = 0;
 	}
 	}
 
 
 	int PolygonShape::getPoints(lua_State * L)
 	int PolygonShape::getPoints(lua_State * L)

+ 5 - 0
src/modules/physics/box2d/Shape.cpp

@@ -48,6 +48,11 @@ namespace box2d
 
 
 		delete data;
 		delete data;
 		data = 0;
 		data = 0;
+
+		body->body->DestroyShape(shape);
+		shape = 0;
+
+		body->release();
 	}
 	}
 
 
 	Shape::Type Shape::getType() const
 	Shape::Type Shape::getType() const

+ 5 - 1
src/modules/physics/box2d/wrap_Body.cpp

@@ -400,8 +400,12 @@ namespace box2d
 
 
 	int w_Body_destroy(lua_State * L)
 	int w_Body_destroy(lua_State * L)
 	{
 	{
-		Body * t = luax_checkbody(L, 1);
+		Proxy * p = (Proxy *)lua_touserdata(L, 1);
+		p->own = false;
+
+		Body * t = (Body *)p->data;
 		t->release();
 		t->release();
+
 		return 0;
 		return 0;
 	}
 	}
 
 

+ 5 - 1
src/modules/physics/box2d/wrap_Joint.cpp

@@ -80,8 +80,12 @@ namespace box2d
 
 
 	int w_Joint_destroy(lua_State * L)
 	int w_Joint_destroy(lua_State * L)
 	{
 	{
-		Joint * t = luax_checkjoint(L, 1);
+		Proxy * p = (Proxy *)lua_touserdata(L, 1);
+		p->own = false;
+
+		Joint * t = (Joint *)p->data;
 		t->release();
 		t->release();
+
 		return 0;
 		return 0;
 	}
 	}
 
 

+ 4 - 1
src/modules/physics/box2d/wrap_Shape.cpp

@@ -200,7 +200,10 @@ namespace box2d
 
 
 	int w_Shape_destroy(lua_State * L)
 	int w_Shape_destroy(lua_State * L)
 	{
 	{
-		Shape * t = luax_checkshape(L, 1);
+		Proxy * p = (Proxy *)lua_touserdata(L, 1);
+		p->own = false;
+
+		Shape * t = (Shape *)p->data;
 		t->release();
 		t->release();
 		return 0;
 		return 0;
 	}
 	}