From 4f6e956f850b8cfb099e0a697280945c530aafb4 Mon Sep 17 00:00:00 2001 From: Alex Szpakowski Date: Sun, 11 Aug 2013 17:50:57 -0300 Subject: [PATCH] Fixed ChainShape:getChildEdge crashing --- src/modules/physics/box2d/ChainShape.cpp | 19 +++++++++++-------- src/modules/physics/box2d/wrap_ChainShape.cpp | 3 ++- 2 files changed, 13 insertions(+), 9 deletions(-) diff --git a/src/modules/physics/box2d/ChainShape.cpp b/src/modules/physics/box2d/ChainShape.cpp index 6972e0a19..94ae8e1d9 100644 --- a/src/modules/physics/box2d/ChainShape.cpp +++ b/src/modules/physics/box2d/ChainShape.cpp @@ -70,16 +70,19 @@ void ChainShape::setPrevVertex(float x, float y) EdgeShape *ChainShape::getChildEdge(int index) const { b2ChainShape *c = (b2ChainShape *)shape; - b2EdgeShape e; - c->GetChildEdge(&e, index); - EdgeShape *edge = (EdgeShape *)Memoizer::find(&e); - if (!edge) - return new EdgeShape(&e); - else + b2EdgeShape *e = new b2EdgeShape; + + try { - edge->retain(); - return edge; + c->GetChildEdge(e, index); } + catch (love::Exception &ex) + { + delete e; + throw; + } + + return new EdgeShape(e, true); } int ChainShape::getChildCount() const diff --git a/src/modules/physics/box2d/wrap_ChainShape.cpp b/src/modules/physics/box2d/wrap_ChainShape.cpp index cfbeb24aa..5cc905e1b 100644 --- a/src/modules/physics/box2d/wrap_ChainShape.cpp +++ b/src/modules/physics/box2d/wrap_ChainShape.cpp @@ -63,7 +63,8 @@ int w_ChainShape_getChildEdge(lua_State *L) { ChainShape *c = luax_checkchainshape(L, 1); 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); return 1; }