diff --git a/examples/DeformableDemo/ClothFriction.cpp b/examples/DeformableDemo/ClothFriction.cpp index 5ea2d8701..e2aa2c0b3 100644 --- a/examples/DeformableDemo/ClothFriction.cpp +++ b/examples/DeformableDemo/ClothFriction.cpp @@ -29,13 +29,16 @@ class ClothFriction : public CommonRigidBodyBase { btAlignedObjectArray 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; diff --git a/src/BulletSoftBody/btSoftBody.cpp b/src/BulletSoftBody/btSoftBody.cpp index f6812fd10..d14ef82dc 100644 --- a/src/BulletSoftBody/btSoftBody.cpp +++ b/src/BulletSoftBody/btSoftBody.cpp @@ -105,7 +105,17 @@ static inline btDbvtNode* buildTreeBottomUp(btAlignedObjectArray& 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];