diff --git a/src/BulletSoftBody/btSoftBody.cpp b/src/BulletSoftBody/btSoftBody.cpp index 036022379..832a697bf 100644 --- a/src/BulletSoftBody/btSoftBody.cpp +++ b/src/BulletSoftBody/btSoftBody.cpp @@ -97,8 +97,7 @@ btSoftBody::~btSoftBody() delete m_collisionShape; int i; - for(i=0;im_leaf) m_cdbvt.remove(c->m_leaf); +c->~Cluster(); +btAlignedFree(c); +m_clusters.remove(c); +} + +// +void btSoftBody::releaseClusters() +{ +while(m_clusters.size()>0) releaseCluster(0); +} + // int btSoftBody::generateClusters(int k,int maxiterations) { - int i; - -for(i=0;im_leaf) m_cdbvt.remove(m_clusters[i]->m_leaf); - btAlignedFree(m_clusters[i]); - } +int i; +releaseClusters(); m_clusters.resize(btMin(k,m_nodes.size())); - - - for(i=0;i0) { if(m_clusters[i]->m_nodes.size()==0) { - btAlignedFree(m_clusters[i]); - btSwap(m_clusters[i],m_clusters[m_clusters.size()-1]); - m_clusters.pop_back(); - --i; + releaseCluster(i--); } } diff --git a/src/BulletSoftBody/btSoftBody.h b/src/BulletSoftBody/btSoftBody.h index 2131ead7a..3f0e75eae 100644 --- a/src/BulletSoftBody/btSoftBody.h +++ b/src/BulletSoftBody/btSoftBody.h @@ -717,6 +717,9 @@ public: Material* mat=0); /* Randomize constraints to reduce solver bias */ void randomizeConstraints(); + /* Release clusters */ + void releaseCluster(int index); + void releaseClusters(); /* Generate clusters (K-mean) */ int generateClusters(int k,int maxiterations=8192); /* Refine */