Fixed ChainShape:getChildEdge crashing

This commit is contained in:
Alex Szpakowski
2013-08-11 17:50:57 -03:00
parent 2561ace2d6
commit 4f6e956f85
2 changed files with 13 additions and 9 deletions
+11 -8
View File
@@ -70,16 +70,19 @@ void ChainShape::setPrevVertex(float x, float y)
EdgeShape *ChainShape::getChildEdge(int index) const EdgeShape *ChainShape::getChildEdge(int index) const
{ {
b2ChainShape *c = (b2ChainShape *)shape; b2ChainShape *c = (b2ChainShape *)shape;
b2EdgeShape e; b2EdgeShape *e = new b2EdgeShape;
c->GetChildEdge(&e, index);
EdgeShape *edge = (EdgeShape *)Memoizer::find(&e); try
if (!edge)
return new EdgeShape(&e);
else
{ {
edge->retain(); c->GetChildEdge(e, index);
return edge;
} }
catch (love::Exception &ex)
{
delete e;
throw;
}
return new EdgeShape(e, true);
} }
int ChainShape::getChildCount() const int ChainShape::getChildCount() const
@@ -63,7 +63,8 @@ int w_ChainShape_getChildEdge(lua_State *L)
{ {
ChainShape *c = luax_checkchainshape(L, 1); ChainShape *c = luax_checkchainshape(L, 1);
int index = luaL_checkint(L, 2) - 1; // Convert from 1-based index int index = luaL_checkint(L, 2) - 1; // Convert from 1-based index
EdgeShape *e = c->getChildEdge(index); EdgeShape *e = 0;
ASSERT_GUARD(e = c->getChildEdge(index);)
luax_newtype(L, "EdgeShape", PHYSICS_EDGE_SHAPE_T, e); luax_newtype(L, "EdgeShape", PHYSICS_EDGE_SHAPE_T, e);
return 1; return 1;
} }