From 2a88ed1fa53ca9f790e7b1d18d2762c25e2d5cdd Mon Sep 17 00:00:00 2001 From: Bill Meltsner Date: Sat, 4 Feb 2012 18:55:48 -0500 Subject: [PATCH] Fix issues with Shape retention in Fixture:getShape() --- src/modules/physics/box2d/Fixture.cpp | 7 ++++++- src/modules/physics/box2d/wrap_Fixture.cpp | 1 - 2 files changed, 6 insertions(+), 2 deletions(-) diff --git a/src/modules/physics/box2d/Fixture.cpp b/src/modules/physics/box2d/Fixture.cpp index 65326a3a2..0ac32405b 100644 --- a/src/modules/physics/box2d/Fixture.cpp +++ b/src/modules/physics/box2d/Fixture.cpp @@ -128,7 +128,12 @@ namespace box2d return NULL; Shape * s = (Shape *)Memoizer::find(fixture->GetShape()); if (!s) - s = new Shape(fixture->GetShape()); + { + b2BlockAllocator a; + s = new Shape(fixture->GetShape()->Clone(&a)); + } + else + s->retain(); return s; } diff --git a/src/modules/physics/box2d/wrap_Fixture.cpp b/src/modules/physics/box2d/wrap_Fixture.cpp index 81ed62ce3..f57d13616 100644 --- a/src/modules/physics/box2d/wrap_Fixture.cpp +++ b/src/modules/physics/box2d/wrap_Fixture.cpp @@ -121,7 +121,6 @@ namespace box2d Shape * shape = t->getShape(); if (shape == 0) return 0; - shape->retain(); switch (shape->getType()) { case Shape::SHAPE_EDGE: luax_newtype(L, "EdgeShape", PHYSICS_EDGE_SHAPE_T, (void*)shape);