Browse Source

Fix Fixture memory management issues

--HG--
branch : box2d-update
Bill Meltsner 14 years ago
parent
commit
8ae43be1fe
2 changed files with 6 additions and 9 deletions
  1. 6 8
      src/modules/physics/box2d/Fixture.cpp
  2. 0 1
      src/modules/physics/box2d/Fixture.h

+ 6 - 8
src/modules/physics/box2d/Fixture.cpp

@@ -47,7 +47,6 @@ namespace box2d
 		def.userData = (void *)data;
 		def.density = density;
 		fixture = body->body->CreateFixture(&def);
-		shape = new Shape(fixture->GetShape());
 		Memoizer::add(fixture, this);
 	}
 	
@@ -57,10 +56,7 @@ namespace box2d
 		data = (fixtureudata *)f->GetUserData();
 		body = (Body *)Memoizer::find(f->GetBody());
 		if (!body) body = new Body(f->GetBody());
-		body->retain();
-		shape = (Shape *)Memoizer::find(f->GetShape());
-		if (!shape) shape = new Shape(f->GetShape());
-		else shape->retain();
+		else body->retain();
 		Memoizer::add(fixture, this);
 	}
 
@@ -77,12 +73,11 @@ namespace box2d
 		fixture = 0;
 
 		body->release();
-		shape->release();
 	}
 
 	Shape::Type Fixture::getType() const
 	{
-		return shape->getType();
+		return Shape(fixture->GetShape()).getType();
 	}
 
 	void Fixture::setFriction(float friction)
@@ -132,7 +127,10 @@ namespace box2d
 	
 	Shape * Fixture::getShape() const
 	{
-		return shape;
+		if (!fixture->GetShape()) return NULL;
+		Shape * s = (Shape *)Memoizer::find(fixture->GetShape());
+		if (!s) s = new Shape(fixture->GetShape());
+		return s;
 	}
 	
 	Fixture * Fixture::getNext() const

+ 0 - 1
src/modules/physics/box2d/Fixture.h

@@ -60,7 +60,6 @@ namespace box2d
 	protected:
 		
 		Body * body;
-		Shape * shape;
 		b2Fixture * fixture;
 		fixtureudata * data;