diff --git a/src/modules/physics/box2d/ChainShape.cpp b/src/modules/physics/box2d/ChainShape.cpp index 693719a67..2a0af58b5 100644 --- a/src/modules/physics/box2d/ChainShape.cpp +++ b/src/modules/physics/box2d/ChainShape.cpp @@ -39,6 +39,8 @@ namespace box2d ChainShape::~ChainShape() { + delete shape; + shape = NULL; } void ChainShape::setNextVertex(float x, float y) diff --git a/src/modules/physics/box2d/CircleShape.cpp b/src/modules/physics/box2d/CircleShape.cpp index d8b619799..614f04621 100644 --- a/src/modules/physics/box2d/CircleShape.cpp +++ b/src/modules/physics/box2d/CircleShape.cpp @@ -37,6 +37,7 @@ namespace box2d CircleShape::~CircleShape() { + delete shape; shape = NULL; } diff --git a/src/modules/physics/box2d/EdgeShape.cpp b/src/modules/physics/box2d/EdgeShape.cpp index 196ea9940..3d0c6a8d5 100644 --- a/src/modules/physics/box2d/EdgeShape.cpp +++ b/src/modules/physics/box2d/EdgeShape.cpp @@ -37,6 +37,8 @@ namespace box2d EdgeShape::~EdgeShape() { + delete shape; + shape = NULL; } } // box2d diff --git a/src/modules/physics/box2d/Physics.cpp b/src/modules/physics/box2d/Physics.cpp index 51b3c0443..cd3c8ba94 100644 --- a/src/modules/physics/box2d/Physics.cpp +++ b/src/modules/physics/box2d/Physics.cpp @@ -64,10 +64,10 @@ namespace box2d CircleShape * Physics::newCircleShape(float x, float y, float radius) { - b2CircleShape s; - s.m_p = b2Vec2(x, y); - s.m_radius = radius; - return new CircleShape(&s); + b2CircleShape *s = new b2CircleShape(); + s->m_p = b2Vec2(x, y); + s->m_radius = radius; + return new CircleShape(s); } PolygonShape * Physics::newRectangleShape(float w, float h) @@ -82,16 +82,16 @@ namespace box2d PolygonShape * Physics::newRectangleShape(float x, float y, float w, float h, float angle) { - b2PolygonShape s; - s.SetAsBox(w/2.0f, h/2.0f, b2Vec2(x, y), angle); - return new PolygonShape(&s); + b2PolygonShape* s = new b2PolygonShape(); + s->SetAsBox(w/2.0f, h/2.0f, b2Vec2(x, y), angle); + return new PolygonShape(s); } EdgeShape * Physics::newEdgeShape(float x1, float y1, float x2, float y2) { - b2EdgeShape s; - s.Set(b2Vec2(x1, y1), b2Vec2(x2, y2)); - return new EdgeShape(&s); + b2EdgeShape* s = new b2EdgeShape(); + s->Set(b2Vec2(x1, y1), b2Vec2(x2, y2)); + return new EdgeShape(s); } int Physics::newPolygonShape(lua_State * L) @@ -101,9 +101,9 @@ namespace box2d // 3 vertices love::luax_assert_argc(L, 2 * 3); - b2PolygonShape s; + b2PolygonShape* s = new b2PolygonShape(); - std::vector points(s.m_vertexCount); + std::vector points(s->m_vertexCount); std::vector convex_hull; for(int i = 0;iSet(vecs, count); - PolygonShape * p = new PolygonShape(&s); + PolygonShape * p = new PolygonShape(s); delete[] vecs; luax_newtype(L, "PolygonShape", PHYSICS_POLYGON_SHAPE_T, (void*)p); @@ -144,7 +144,7 @@ namespace box2d int argc = lua_gettop(L)-1; // first argument is looping int vcount = (int)argc/2; - b2ChainShape s; + b2ChainShape* s = new b2ChainShape(); bool loop = luax_toboolean(L, 1); @@ -159,11 +159,11 @@ namespace box2d } if (loop) - s.CreateLoop(vecs, vcount); + s->CreateLoop(vecs, vcount); else - s.CreateChain(vecs, vcount); + s->CreateChain(vecs, vcount); - ChainShape * c = new ChainShape(&s); + ChainShape * c = new ChainShape(s); delete[] vecs; luax_newtype(L, "ChainShape", PHYSICS_CHAIN_SHAPE_T, (void*)c); diff --git a/src/modules/physics/box2d/PolygonShape.cpp b/src/modules/physics/box2d/PolygonShape.cpp index ec3ba787e..84feefbe1 100644 --- a/src/modules/physics/box2d/PolygonShape.cpp +++ b/src/modules/physics/box2d/PolygonShape.cpp @@ -37,6 +37,8 @@ namespace box2d PolygonShape::~PolygonShape() { + delete shape; + shape = NULL; } int PolygonShape::getPoints(lua_State * L)