mirror of
https://github.com/love2d/love.git
synced 2026-08-19 20:19:42 +02:00
Fix Shape memory management
--HG-- branch : box2d-update
This commit is contained in:
@@ -39,6 +39,8 @@ namespace box2d
|
|||||||
|
|
||||||
ChainShape::~ChainShape()
|
ChainShape::~ChainShape()
|
||||||
{
|
{
|
||||||
|
delete shape;
|
||||||
|
shape = NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
void ChainShape::setNextVertex(float x, float y)
|
void ChainShape::setNextVertex(float x, float y)
|
||||||
|
|||||||
@@ -37,6 +37,7 @@ namespace box2d
|
|||||||
|
|
||||||
CircleShape::~CircleShape()
|
CircleShape::~CircleShape()
|
||||||
{
|
{
|
||||||
|
delete shape;
|
||||||
shape = NULL;
|
shape = NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -37,6 +37,8 @@ namespace box2d
|
|||||||
|
|
||||||
EdgeShape::~EdgeShape()
|
EdgeShape::~EdgeShape()
|
||||||
{
|
{
|
||||||
|
delete shape;
|
||||||
|
shape = NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
} // box2d
|
} // box2d
|
||||||
|
|||||||
@@ -64,10 +64,10 @@ namespace box2d
|
|||||||
|
|
||||||
CircleShape * Physics::newCircleShape(float x, float y, float radius)
|
CircleShape * Physics::newCircleShape(float x, float y, float radius)
|
||||||
{
|
{
|
||||||
b2CircleShape s;
|
b2CircleShape *s = new b2CircleShape();
|
||||||
s.m_p = b2Vec2(x, y);
|
s->m_p = b2Vec2(x, y);
|
||||||
s.m_radius = radius;
|
s->m_radius = radius;
|
||||||
return new CircleShape(&s);
|
return new CircleShape(s);
|
||||||
}
|
}
|
||||||
|
|
||||||
PolygonShape * Physics::newRectangleShape(float w, float h)
|
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)
|
PolygonShape * Physics::newRectangleShape(float x, float y, float w, float h, float angle)
|
||||||
{
|
{
|
||||||
b2PolygonShape s;
|
b2PolygonShape* s = new b2PolygonShape();
|
||||||
s.SetAsBox(w/2.0f, h/2.0f, b2Vec2(x, y), angle);
|
s->SetAsBox(w/2.0f, h/2.0f, b2Vec2(x, y), angle);
|
||||||
return new PolygonShape(&s);
|
return new PolygonShape(s);
|
||||||
}
|
}
|
||||||
|
|
||||||
EdgeShape * Physics::newEdgeShape(float x1, float y1, float x2, float y2)
|
EdgeShape * Physics::newEdgeShape(float x1, float y1, float x2, float y2)
|
||||||
{
|
{
|
||||||
b2EdgeShape s;
|
b2EdgeShape* s = new b2EdgeShape();
|
||||||
s.Set(b2Vec2(x1, y1), b2Vec2(x2, y2));
|
s->Set(b2Vec2(x1, y1), b2Vec2(x2, y2));
|
||||||
return new EdgeShape(&s);
|
return new EdgeShape(s);
|
||||||
}
|
}
|
||||||
|
|
||||||
int Physics::newPolygonShape(lua_State * L)
|
int Physics::newPolygonShape(lua_State * L)
|
||||||
@@ -101,9 +101,9 @@ namespace box2d
|
|||||||
// 3 vertices
|
// 3 vertices
|
||||||
love::luax_assert_argc(L, 2 * 3);
|
love::luax_assert_argc(L, 2 * 3);
|
||||||
|
|
||||||
b2PolygonShape s;
|
b2PolygonShape* s = new b2PolygonShape();
|
||||||
|
|
||||||
std::vector<point2d> points(s.m_vertexCount);
|
std::vector<point2d> points(s->m_vertexCount);
|
||||||
std::vector<point2d> convex_hull;
|
std::vector<point2d> convex_hull;
|
||||||
|
|
||||||
for(int i = 0;i<vcount;i++)
|
for(int i = 0;i<vcount;i++)
|
||||||
@@ -129,9 +129,9 @@ namespace box2d
|
|||||||
vecs[i].Set(convex_hull[i].x, convex_hull[i].y);
|
vecs[i].Set(convex_hull[i].x, convex_hull[i].y);
|
||||||
}
|
}
|
||||||
|
|
||||||
s.Set(vecs, count);
|
s->Set(vecs, count);
|
||||||
|
|
||||||
PolygonShape * p = new PolygonShape(&s);
|
PolygonShape * p = new PolygonShape(s);
|
||||||
delete[] vecs;
|
delete[] vecs;
|
||||||
|
|
||||||
luax_newtype(L, "PolygonShape", PHYSICS_POLYGON_SHAPE_T, (void*)p);
|
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 argc = lua_gettop(L)-1; // first argument is looping
|
||||||
int vcount = (int)argc/2;
|
int vcount = (int)argc/2;
|
||||||
|
|
||||||
b2ChainShape s;
|
b2ChainShape* s = new b2ChainShape();
|
||||||
|
|
||||||
bool loop = luax_toboolean(L, 1);
|
bool loop = luax_toboolean(L, 1);
|
||||||
|
|
||||||
@@ -159,11 +159,11 @@ namespace box2d
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (loop)
|
if (loop)
|
||||||
s.CreateLoop(vecs, vcount);
|
s->CreateLoop(vecs, vcount);
|
||||||
else
|
else
|
||||||
s.CreateChain(vecs, vcount);
|
s->CreateChain(vecs, vcount);
|
||||||
|
|
||||||
ChainShape * c = new ChainShape(&s);
|
ChainShape * c = new ChainShape(s);
|
||||||
delete[] vecs;
|
delete[] vecs;
|
||||||
|
|
||||||
luax_newtype(L, "ChainShape", PHYSICS_CHAIN_SHAPE_T, (void*)c);
|
luax_newtype(L, "ChainShape", PHYSICS_CHAIN_SHAPE_T, (void*)c);
|
||||||
|
|||||||
@@ -37,6 +37,8 @@ namespace box2d
|
|||||||
|
|
||||||
PolygonShape::~PolygonShape()
|
PolygonShape::~PolygonShape()
|
||||||
{
|
{
|
||||||
|
delete shape;
|
||||||
|
shape = NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
int PolygonShape::getPoints(lua_State * L)
|
int PolygonShape::getPoints(lua_State * L)
|
||||||
|
|||||||
Reference in New Issue
Block a user