fixed some outstanding issues with Bullet soft bodies:
[blender.git] / extern / bullet2 / src / BulletSoftBody / btSoftBodyRigidBodyCollisionConfiguration.cpp
index e62f35567b098fe67d9fbaac97f501ff0239f47f..e79dd214e6200e911f6856237198bad16a79dc57 100644 (file)
@@ -18,6 +18,8 @@ subject to the following restrictions:
 #include "btSoftBodyConcaveCollisionAlgorithm.h"
 #include "btSoftSoftCollisionAlgorithm.h"
 
+#include "LinearMath/btPoolAllocator.h"
+
 #define ENABLE_SOFTBODY_CONCAVE_COLLISIONS 1
 
 btSoftBodyRigidBodyCollisionConfiguration::btSoftBodyRigidBodyCollisionConfiguration(const btDefaultCollisionConstructionInfo& constructionInfo)
@@ -44,6 +46,31 @@ btSoftBodyRigidBodyCollisionConfiguration::btSoftBodyRigidBodyCollisionConfigura
        m_swappedSoftRigidConcaveCreateFunc->m_swapped=true;
 #endif
 
+       //replace pool by a new one, with potential larger size
+       
+       if (m_ownsCollisionAlgorithmPool && m_collisionAlgorithmPool)
+       {
+               int curElemSize = m_collisionAlgorithmPool->getElementSize();
+               ///calculate maximum element size, big enough to fit any collision algorithm in the memory pool
+               
+               
+               int maxSize0 = sizeof(btSoftSoftCollisionAlgorithm);
+               int maxSize1 = sizeof(btSoftRigidCollisionAlgorithm);
+               int maxSize2 = sizeof(btSoftBodyConcaveCollisionAlgorithm);
+
+               int     collisionAlgorithmMaxElementSize = btMax(maxSize0,maxSize1);
+               collisionAlgorithmMaxElementSize = btMax(collisionAlgorithmMaxElementSize,maxSize2);
+               if (collisionAlgorithmMaxElementSize > curElemSize)
+               {
+                       btAlignedFree(m_collisionAlgorithmPool);
+                       void* mem = btAlignedAlloc(sizeof(btPoolAllocator),16);
+                       m_collisionAlgorithmPool = new(mem) btPoolAllocator(collisionAlgorithmMaxElementSize,constructionInfo.m_defaultMaxCollisionAlgorithmPoolSize);
+               }
+       }
+
+
+
+
 }
 
 btSoftBodyRigidBodyCollisionConfiguration::~btSoftBodyRigidBodyCollisionConfiguration()