Fix Fixture:getShape. Resolves issue #1319.

--HG--
branch : minor
This commit is contained in:
Alex Szpakowski
2017-09-22 20:31:24 -03:00
parent 4ee85e1793
commit 8ea2f09a1c
4 changed files with 52 additions and 17 deletions
+37 -7
View File
@@ -76,9 +76,39 @@ Fixture::~Fixture()
delete udata;
}
Shape::Type Fixture::getType() const
void Fixture::checkCreateShape()
{
return Shape(fixture->GetShape(), false).getType();
if (shape.get() != nullptr || fixture == nullptr || fixture->GetShape() == nullptr)
return;
b2Shape *bshape = fixture->GetShape();
switch (bshape->GetType())
{
case b2Shape::e_circle:
shape.set(new CircleShape((b2CircleShape *) bshape, false), Acquire::NORETAIN);
break;
case b2Shape::e_edge:
shape.set(new EdgeShape((b2EdgeShape *) bshape, false), Acquire::NORETAIN);
break;
case b2Shape::e_polygon:
shape.set(new PolygonShape((b2PolygonShape *) bshape, false), Acquire::NORETAIN);
break;
case b2Shape::e_chain:
shape.set(new ChainShape((b2ChainShape *) bshape, false), Acquire::NORETAIN);
break;
default:
break;
}
}
Shape::Type Fixture::getType()
{
checkCreateShape();
if (shape.get() == nullptr)
return Shape::SHAPE_INVALID;
else
return shape->getType();
}
void Fixture::setFriction(float friction)
@@ -126,12 +156,10 @@ Body *Fixture::getBody() const
return body;
}
Shape *Fixture::getShape() const
Shape *Fixture::getShape()
{
if (!fixture->GetShape())
return nullptr;
return new Shape(fixture->GetShape(), false);
checkCreateShape();
return shape;
}
bool Fixture::isValid() const
@@ -329,6 +357,8 @@ void Fixture::destroy(bool implicit)
return;
}
shape.set(nullptr);
if (!implicit && fixture != nullptr)
body->body->DestroyFixture(fixture);
Memoizer::remove(fixture);