when a compound shape is deleted, delete the children, as well

This commit is contained in:
Seth Alves 2015-03-25 06:51:00 -07:00
parent e0f491bcfd
commit 719dae61a9
2 changed files with 14 additions and 0 deletions

View file

@ -20,6 +20,8 @@
// translates between ShapeInfo and btShape
namespace ShapeInfoUtil {
// XXX is collectInfoFromShape no longer strictly needed?
void collectInfoFromShape(const btCollisionShape* shape, ShapeInfo& info);
btCollisionShape* createShapeFromInfo(const ShapeInfo& info);

View file

@ -100,6 +100,18 @@ void ShapeManager::collectGarbage() {
DoubleHashKey& key = _pendingGarbage[i];
ShapeReference* shapeRef = _shapeMap.find(key);
if (shapeRef && shapeRef->refCount == 0) {
// if the shape we're about to delete is compound, delete the children first.
auto shapeType = ShapeInfoUtil::fromBulletShapeType(shapeRef->shape->getShapeType());
if (shapeType == SHAPE_TYPE_COMPOUND) {
const btCompoundShape* compoundShape = static_cast<const btCompoundShape*>(shapeRef->shape);
const int numChildShapes = compoundShape->getNumChildShapes();
QVector<QVector<glm::vec3>> points;
for (int i = 0; i < numChildShapes; i ++) {
const btCollisionShape* childShape = compoundShape->getChildShape(i);
delete childShape;
}
}
delete shapeRef->shape;
_shapeMap.remove(key);
}