btSoftBody clusters memory leak fixed.
This commit is contained in:
@@ -97,8 +97,7 @@ btSoftBody::~btSoftBody()
|
|||||||
delete m_collisionShape;
|
delete m_collisionShape;
|
||||||
int i;
|
int i;
|
||||||
|
|
||||||
for(i=0;i<m_clusters.size();++i)
|
releaseClusters();
|
||||||
btAlignedFree(m_clusters[i]);
|
|
||||||
for(i=0;i<m_materials.size();++i)
|
for(i=0;i<m_materials.size();++i)
|
||||||
btAlignedFree(m_materials[i]);
|
btAlignedFree(m_materials[i]);
|
||||||
for(i=0;i<m_joints.size();++i)
|
for(i=0;i<m_joints.size();++i)
|
||||||
@@ -748,20 +747,28 @@ int i,ni;
|
|||||||
#undef NEXTRAND
|
#undef NEXTRAND
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//
|
||||||
|
void btSoftBody::releaseCluster(int index)
|
||||||
|
{
|
||||||
|
Cluster* c=m_clusters[index];
|
||||||
|
if(c->m_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 btSoftBody::generateClusters(int k,int maxiterations)
|
||||||
{
|
{
|
||||||
int i;
|
int i;
|
||||||
|
releaseClusters();
|
||||||
for(i=0;i<m_clusters.size();++i)
|
|
||||||
{
|
|
||||||
if(m_clusters[i]->m_leaf) m_cdbvt.remove(m_clusters[i]->m_leaf);
|
|
||||||
btAlignedFree(m_clusters[i]);
|
|
||||||
}
|
|
||||||
m_clusters.resize(btMin(k,m_nodes.size()));
|
m_clusters.resize(btMin(k,m_nodes.size()));
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
for(i=0;i<m_clusters.size();++i)
|
for(i=0;i<m_clusters.size();++i)
|
||||||
{
|
{
|
||||||
m_clusters[i] = new(btAlignedAlloc(sizeof(Cluster),16)) Cluster();
|
m_clusters[i] = new(btAlignedAlloc(sizeof(Cluster),16)) Cluster();
|
||||||
@@ -870,10 +877,7 @@ if(k>0)
|
|||||||
{
|
{
|
||||||
if(m_clusters[i]->m_nodes.size()==0)
|
if(m_clusters[i]->m_nodes.size()==0)
|
||||||
{
|
{
|
||||||
btAlignedFree(m_clusters[i]);
|
releaseCluster(i--);
|
||||||
btSwap(m_clusters[i],m_clusters[m_clusters.size()-1]);
|
|
||||||
m_clusters.pop_back();
|
|
||||||
--i;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -717,6 +717,9 @@ public:
|
|||||||
Material* mat=0);
|
Material* mat=0);
|
||||||
/* Randomize constraints to reduce solver bias */
|
/* Randomize constraints to reduce solver bias */
|
||||||
void randomizeConstraints();
|
void randomizeConstraints();
|
||||||
|
/* Release clusters */
|
||||||
|
void releaseCluster(int index);
|
||||||
|
void releaseClusters();
|
||||||
/* Generate clusters (K-mean) */
|
/* Generate clusters (K-mean) */
|
||||||
int generateClusters(int k,int maxiterations=8192);
|
int generateClusters(int k,int maxiterations=8192);
|
||||||
/* Refine */
|
/* Refine */
|
||||||
|
|||||||
Reference in New Issue
Block a user