Merge pull request #2641 from erwincoumans/master

fix memleak due to custom container, release memory of m_deformableBodySolver in ClothFriction demo
This commit is contained in:
erwincoumans
2020-02-22 11:18:41 -08:00
committed by GitHub
2 changed files with 20 additions and 5 deletions

View File

@@ -29,13 +29,16 @@
class ClothFriction : public CommonRigidBodyBase
{
btAlignedObjectArray<btDeformableLagrangianForce*> m_forces;
btDeformableBodySolver* m_deformableBodySolver;
public:
ClothFriction(struct GUIHelperInterface* helper)
: CommonRigidBodyBase(helper)
: CommonRigidBodyBase(helper),
m_deformableBodySolver(0)
{
}
virtual ~ClothFriction()
{
}
void initPhysics();
@@ -94,14 +97,14 @@ void ClothFriction::initPhysics()
m_dispatcher = new btCollisionDispatcher(m_collisionConfiguration);
m_broadphase = new btDbvtBroadphase();
btDeformableBodySolver* deformableBodySolver = new btDeformableBodySolver();
m_deformableBodySolver = new btDeformableBodySolver();
///the default constraint solver. For parallel processing you can use a different solver (see Extras/BulletMultiThreaded)
btDeformableMultiBodyConstraintSolver* sol = new btDeformableMultiBodyConstraintSolver();
sol->setDeformableSolver(deformableBodySolver);
sol->setDeformableSolver(m_deformableBodySolver);
m_solver = sol;
m_dynamicsWorld = new btDeformableMultiBodyDynamicsWorld(m_dispatcher, m_broadphase, sol, m_collisionConfiguration, deformableBodySolver);
m_dynamicsWorld = new btDeformableMultiBodyDynamicsWorld(m_dispatcher, m_broadphase, sol, m_collisionConfiguration, m_deformableBodySolver);
btVector3 gravity = btVector3(0, -10, 0);
m_dynamicsWorld->setGravity(gravity);
getDeformableDynamicsWorld()->getWorldInfo().m_gravity = gravity;
@@ -240,6 +243,8 @@ void ClothFriction::exitPhysics()
delete m_solver;
delete m_deformableBodySolver;
delete m_broadphase;
delete m_dispatcher;

View File

@@ -105,7 +105,17 @@ static inline btDbvtNode* buildTreeBottomUp(btAlignedObjectArray<btDbvtNode*>& l
}
}
leafNodes = newLeafNodes;
adj = newAdj;
//this assignment leaks memory, the assignment doesn't do a deep copy, for now a manual copy
//adj = newAdj;
adj.clear();
adj.resize(newAdj.size());
for (int i = 0; i < newAdj.size(); i++)
{
for (int j = 0; j < newAdj[i].size(); j++)
{
adj[i].push_back(newAdj[i][j]);
}
}
N = leafNodes.size();
}
return leafNodes[0];