diff options
author | ejcoumans <ejcoumans@08e121b0-ae19-0410-a57b-3be3395fd4fd> | 2007-10-22 22:23:10 +0000 |
---|---|---|
committer | ejcoumans <ejcoumans@08e121b0-ae19-0410-a57b-3be3395fd4fd> | 2007-10-22 22:23:10 +0000 |
commit | ec76f2e0a3fc1497a4b7e2ebb33835c4b09a264e (patch) | |
tree | 2e126d6076e630acef9a1283b9819e3a2937b3d3 /src/BulletCollision | |
parent | 1b70c4e5c97d3b5d4ddf35e3f916f6fbb02cb654 (diff) | |
download | bullet3-ec76f2e0a3fc1497a4b7e2ebb33835c4b09a264e.tar.gz |
- keep track of all memory allocations (gNumAllignedAllocs/gNumAllignedFree)
All memory allocations in Bullet go through btAlignedAlloc/btAlignedFree
Fix in hinge constraint constructors, thanks Marcus Hennix!
Diffstat (limited to 'src/BulletCollision')
10 files changed, 96 insertions, 68 deletions
diff --git a/src/BulletCollision/BroadphaseCollision/btMultiSapBroadphase.cpp b/src/BulletCollision/BroadphaseCollision/btMultiSapBroadphase.cpp index 8ac77b2f3..a75689c99 100644 --- a/src/BulletCollision/BroadphaseCollision/btMultiSapBroadphase.cpp +++ b/src/BulletCollision/BroadphaseCollision/btMultiSapBroadphase.cpp @@ -52,11 +52,12 @@ m_invalidPair(0) }
};
- m_filterCallback = new btMultiSapOverlapFilterCallback();
+ void* mem = btAlignedAlloc(sizeof(btMultiSapOverlapFilterCallback),16);
+ m_filterCallback = new (mem)btMultiSapOverlapFilterCallback();
m_overlappingPairs->setOverlapFilterCallback(m_filterCallback);
-
- m_simpleBroadphase = new btSimpleBroadphase(maxProxies,m_overlappingPairs);
+ mem = btAlignedAlloc(sizeof(btSimpleBroadphase),16);
+ m_simpleBroadphase = new (mem) btSimpleBroadphase(maxProxies,m_overlappingPairs);
}
btMultiSapBroadphase::~btMultiSapBroadphase()
@@ -69,7 +70,8 @@ btMultiSapBroadphase::~btMultiSapBroadphase() btBroadphaseProxy* btMultiSapBroadphase::createProxy( const btVector3& aabbMin, const btVector3& aabbMax,int shapeType,void* userPtr, short int collisionFilterGroup,short int collisionFilterMask, btDispatcher* dispatcher)
{
- btMultiSapProxy* proxy = new btMultiSapProxy(aabbMin, aabbMax,shapeType,userPtr, collisionFilterGroup,collisionFilterMask);
+ void* mem = btAlignedAlloc(sizeof(btMultiSapProxy),16);
+ btMultiSapProxy* proxy = new (mem)btMultiSapProxy(aabbMin, aabbMax,shapeType,userPtr, collisionFilterGroup,collisionFilterMask);
m_multiSapProxies.push_back(proxy);
///we don't pass the userPtr but our multisap proxy. We need to patch this, before processing an actual collision
@@ -77,6 +79,7 @@ btBroadphaseProxy* btMultiSapBroadphase::createProxy( const btVector3& aabbMin, btBroadphaseProxy* simpleProxy = m_simpleBroadphase->createProxy(aabbMin,aabbMax,shapeType,userPtr,collisionFilterGroup,collisionFilterMask, dispatcher);
simpleProxy->m_multiSapParentProxy = proxy;
+ mem = btAlignedAlloc(sizeof(btChildProxy),16);
btChildProxy* childProxyRef = new btChildProxy();
childProxyRef->m_proxy = simpleProxy;
childProxyRef->m_childBroadphase = m_simpleBroadphase;
diff --git a/src/BulletCollision/CollisionDispatch/btCollisionWorld.cpp b/src/BulletCollision/CollisionDispatch/btCollisionWorld.cpp index ba3f52143..b4828508b 100644 --- a/src/BulletCollision/CollisionDispatch/btCollisionWorld.cpp +++ b/src/BulletCollision/CollisionDispatch/btCollisionWorld.cpp @@ -40,9 +40,7 @@ subject to the following restrictions: btCollisionWorld::btCollisionWorld(btDispatcher* dispatcher,btBroadphaseInterface* pairCache, btCollisionConfiguration* collisionConfiguration) :m_dispatcher1(dispatcher), -m_broadphasePairCache(pairCache), -m_ownsDispatcher(false), -m_ownsBroadphasePairCache(false) +m_broadphasePairCache(pairCache) { m_stackAlloc = collisionConfiguration->getStackAllocator(); m_dispatchInfo.m_stackAllocator = m_stackAlloc; @@ -69,10 +67,6 @@ btCollisionWorld::~btCollisionWorld() } } - if (m_ownsDispatcher) - delete m_dispatcher1; - if (m_ownsBroadphasePairCache) - delete m_broadphasePairCache; } diff --git a/src/BulletCollision/CollisionDispatch/btCollisionWorld.h b/src/BulletCollision/CollisionDispatch/btCollisionWorld.h index 0ad2e89f4..bda03cced 100644 --- a/src/BulletCollision/CollisionDispatch/btCollisionWorld.h +++ b/src/BulletCollision/CollisionDispatch/btCollisionWorld.h @@ -92,9 +92,6 @@ protected: btBroadphaseInterface* m_broadphasePairCache; - bool m_ownsDispatcher; - bool m_ownsBroadphasePairCache; - public: //this constructor doesn't own the dispatcher and paircache/broadphase diff --git a/src/BulletCollision/CollisionDispatch/btConvexConvexAlgorithm.cpp b/src/BulletCollision/CollisionDispatch/btConvexConvexAlgorithm.cpp index 76dc2a84d..d1692cdac 100644 --- a/src/BulletCollision/CollisionDispatch/btConvexConvexAlgorithm.cpp +++ b/src/BulletCollision/CollisionDispatch/btConvexConvexAlgorithm.cpp @@ -48,26 +48,16 @@ subject to the following restrictions: -btConvexConvexAlgorithm::CreateFunc::CreateFunc() -{ - m_ownsSolvers = true; - m_simplexSolver = new btVoronoiSimplexSolver(); - m_pdSolver = new btGjkEpaPenetrationDepthSolver; -} + btConvexConvexAlgorithm::CreateFunc::CreateFunc(btSimplexSolverInterface* simplexSolver, btConvexPenetrationDepthSolver* pdSolver) { - m_ownsSolvers = false; m_simplexSolver = simplexSolver; m_pdSolver = pdSolver; } btConvexConvexAlgorithm::CreateFunc::~CreateFunc() { - if (m_ownsSolvers){ - delete m_simplexSolver; - delete m_pdSolver; - } } btConvexConvexAlgorithm::btConvexConvexAlgorithm(btPersistentManifold* mf,const btCollisionAlgorithmConstructionInfo& ci,btCollisionObject* body0,btCollisionObject* body1,btSimplexSolverInterface* simplexSolver, btConvexPenetrationDepthSolver* pdSolver) diff --git a/src/BulletCollision/CollisionDispatch/btConvexConvexAlgorithm.h b/src/BulletCollision/CollisionDispatch/btConvexConvexAlgorithm.h index acc1e1cf7..ca58bce25 100644 --- a/src/BulletCollision/CollisionDispatch/btConvexConvexAlgorithm.h +++ b/src/BulletCollision/CollisionDispatch/btConvexConvexAlgorithm.h @@ -59,10 +59,9 @@ public: { btConvexPenetrationDepthSolver* m_pdSolver; btSimplexSolverInterface* m_simplexSolver; - bool m_ownsSolvers; CreateFunc(btSimplexSolverInterface* simplexSolver, btConvexPenetrationDepthSolver* pdSolver); - CreateFunc(); + virtual ~CreateFunc(); virtual btCollisionAlgorithm* CreateCollisionAlgorithm(btCollisionAlgorithmConstructionInfo& ci, btCollisionObject* body0,btCollisionObject* body1) diff --git a/src/BulletCollision/CollisionDispatch/btDefaultCollisionConfiguration.cpp b/src/BulletCollision/CollisionDispatch/btDefaultCollisionConfiguration.cpp index 2dfdf240b..ce05dc153 100644 --- a/src/BulletCollision/CollisionDispatch/btDefaultCollisionConfiguration.cpp +++ b/src/BulletCollision/CollisionDispatch/btDefaultCollisionConfiguration.cpp @@ -23,6 +23,10 @@ subject to the following restrictions: #include "BulletCollision/CollisionDispatch/btSphereSphereCollisionAlgorithm.h" #include "BulletCollision/CollisionDispatch/btSphereBoxCollisionAlgorithm.h" #include "BulletCollision/CollisionDispatch/btSphereTriangleCollisionAlgorithm.h" +#include "BulletCollision/NarrowPhaseCollision/btGjkEpaPenetrationDepthSolver.h" +#include "BulletCollision/NarrowPhaseCollision/btVoronoiSimplexSolver.h" + + #include "LinearMath/btStackAlloc.h" #include "LinearMath/btPoolAllocator.h" @@ -36,20 +40,36 @@ subject to the following restrictions: btDefaultCollisionConfiguration::btDefaultCollisionConfiguration(btStackAlloc* stackAlloc,btPoolAllocator* persistentManifoldPool,btPoolAllocator* collisionAlgorithmPool) { + void* mem = btAlignedAlloc(sizeof(btVoronoiSimplexSolver),16); + m_simplexSolver = new (mem)btVoronoiSimplexSolver(); + mem = btAlignedAlloc(sizeof(btGjkEpaPenetrationDepthSolver),16); + m_pdSolver = new (mem)btGjkEpaPenetrationDepthSolver; + //default CreationFunctions, filling the m_doubleDispatch table - m_convexConvexCreateFunc = new btConvexConvexAlgorithm::CreateFunc; - m_convexConcaveCreateFunc = new btConvexConcaveCollisionAlgorithm::CreateFunc; - m_swappedConvexConcaveCreateFunc = new btConvexConcaveCollisionAlgorithm::SwappedCreateFunc; - m_compoundCreateFunc = new btCompoundCollisionAlgorithm::CreateFunc; - m_swappedCompoundCreateFunc = new btCompoundCollisionAlgorithm::SwappedCreateFunc; - m_emptyCreateFunc = new btEmptyAlgorithm::CreateFunc; - m_sphereSphereCF = new btSphereSphereCollisionAlgorithm::CreateFunc; - m_sphereBoxCF = new btSphereBoxCollisionAlgorithm::CreateFunc; - m_boxSphereCF = new btSphereBoxCollisionAlgorithm::CreateFunc; + mem = btAlignedAlloc(sizeof(btConvexConvexAlgorithm::CreateFunc),16); + m_convexConvexCreateFunc = new(mem) btConvexConvexAlgorithm::CreateFunc(m_simplexSolver,m_pdSolver); + mem = btAlignedAlloc(sizeof(btConvexConcaveCollisionAlgorithm::CreateFunc),16); + m_convexConcaveCreateFunc = new (mem)btConvexConcaveCollisionAlgorithm::CreateFunc; + mem = btAlignedAlloc(sizeof(btConvexConcaveCollisionAlgorithm::CreateFunc),16); + m_swappedConvexConcaveCreateFunc = new (mem)btConvexConcaveCollisionAlgorithm::SwappedCreateFunc; + mem = btAlignedAlloc(sizeof(btCompoundCollisionAlgorithm::CreateFunc),16); + m_compoundCreateFunc = new (mem)btCompoundCollisionAlgorithm::CreateFunc; + mem = btAlignedAlloc(sizeof(btCompoundCollisionAlgorithm::SwappedCreateFunc),16); + m_swappedCompoundCreateFunc = new (mem)btCompoundCollisionAlgorithm::SwappedCreateFunc; + mem = btAlignedAlloc(sizeof(btEmptyAlgorithm::CreateFunc),16); + m_emptyCreateFunc = new(mem) btEmptyAlgorithm::CreateFunc; + + mem = btAlignedAlloc(sizeof(btSphereSphereCollisionAlgorithm::CreateFunc),16); + m_sphereSphereCF = new(mem) btSphereSphereCollisionAlgorithm::CreateFunc; + mem = btAlignedAlloc(sizeof(btSphereBoxCollisionAlgorithm::CreateFunc),16); + m_sphereBoxCF = new(mem) btSphereBoxCollisionAlgorithm::CreateFunc; + mem = btAlignedAlloc(sizeof(btSphereBoxCollisionAlgorithm::CreateFunc),16); + m_boxSphereCF = new (mem)btSphereBoxCollisionAlgorithm::CreateFunc; m_boxSphereCF->m_swapped = true; - - m_sphereTriangleCF = new btSphereTriangleCollisionAlgorithm::CreateFunc; - m_triangleSphereCF = new btSphereTriangleCollisionAlgorithm::CreateFunc; + mem = btAlignedAlloc(sizeof(btSphereTriangleCollisionAlgorithm::CreateFunc),16); + m_sphereTriangleCF = new (mem)btSphereTriangleCollisionAlgorithm::CreateFunc; + mem = btAlignedAlloc(sizeof(btSphereTriangleCollisionAlgorithm::CreateFunc),16); + m_triangleSphereCF = new (mem)btSphereTriangleCollisionAlgorithm::CreateFunc; m_triangleSphereCF->m_swapped = true; @@ -115,17 +135,20 @@ btDefaultCollisionConfiguration::~btDefaultCollisionConfiguration() btAlignedFree(m_persistentManifoldPool); } - delete m_convexConvexCreateFunc; - delete m_convexConcaveCreateFunc; - delete m_swappedConvexConcaveCreateFunc; - delete m_compoundCreateFunc; - delete m_swappedCompoundCreateFunc; - delete m_emptyCreateFunc; - delete m_sphereSphereCF; - delete m_sphereBoxCF; - delete m_boxSphereCF; - delete m_sphereTriangleCF; - delete m_triangleSphereCF; + btAlignedFree( m_convexConvexCreateFunc); + btAlignedFree( m_convexConcaveCreateFunc); + btAlignedFree( m_swappedConvexConcaveCreateFunc); + btAlignedFree( m_compoundCreateFunc); + btAlignedFree( m_swappedCompoundCreateFunc); + btAlignedFree( m_emptyCreateFunc); + btAlignedFree( m_sphereSphereCF); + btAlignedFree( m_sphereBoxCF); + btAlignedFree( m_boxSphereCF); + btAlignedFree( m_sphereTriangleCF); + btAlignedFree( m_triangleSphereCF); + + btAlignedFree(m_simplexSolver); + btAlignedFree(m_pdSolver); } diff --git a/src/BulletCollision/CollisionDispatch/btDefaultCollisionConfiguration.h b/src/BulletCollision/CollisionDispatch/btDefaultCollisionConfiguration.h index 20f6ecd6e..2e99f1db1 100644 --- a/src/BulletCollision/CollisionDispatch/btDefaultCollisionConfiguration.h +++ b/src/BulletCollision/CollisionDispatch/btDefaultCollisionConfiguration.h @@ -17,6 +17,9 @@ subject to the following restrictions: #define BT_DEFAULT_COLLISION_CONFIGURATION #include "btCollisionConfiguration.h" +class btVoronoiSimplexSolver; +class btGjkEpaPenetrationDepthSolver; + ///btCollisionConfiguration allows to configure Bullet collision detection ///stack allocator, pool memory allocators @@ -35,6 +38,9 @@ class btDefaultCollisionConfiguration : public btCollisionConfiguration btPoolAllocator* m_collisionAlgorithmPool; bool m_ownsCollisionAlgorithmPool; + //default simplex/penetration depth solvers + btVoronoiSimplexSolver* m_simplexSolver; + btGjkEpaPenetrationDepthSolver* m_pdSolver; //default CreationFunctions, filling the m_doubleDispatch table btCollisionAlgorithmCreateFunc* m_convexConvexCreateFunc; diff --git a/src/BulletCollision/CollisionDispatch/btSimulationIslandManager.cpp b/src/BulletCollision/CollisionDispatch/btSimulationIslandManager.cpp index b69fdb279..0cc3ac599 100644 --- a/src/BulletCollision/CollisionDispatch/btSimulationIslandManager.cpp +++ b/src/BulletCollision/CollisionDispatch/btSimulationIslandManager.cpp @@ -241,8 +241,7 @@ void btSimulationIslandManager::buildAndProcessIslands(btDispatcher* dispatcher, #define SPLIT_ISLANDS 1
#ifdef SPLIT_ISLANDS
- btAlignedObjectArray<btPersistentManifold*> islandmanifold;
- islandmanifold.reserve(maxNumManifolds);
+
#endif //SPLIT_ISLANDS
@@ -270,7 +269,7 @@ void btSimulationIslandManager::buildAndProcessIslands(btDispatcher* dispatcher, #ifdef SPLIT_ISLANDS
// //filtering for response
if (dispatcher->needsResponse(colObj0,colObj1))
- islandmanifold.push_back(manifold);
+ m_islandmanifold.push_back(manifold);
#endif //SPLIT_ISLANDS
}
}
@@ -284,10 +283,10 @@ void btSimulationIslandManager::buildAndProcessIslands(btDispatcher* dispatcher, // Sort the vector using predicate and std::sort
//std::sort(islandmanifold.begin(), islandmanifold.end(), btPersistentManifoldSortPredicate);
- int numManifolds = int (islandmanifold.size());
+ int numManifolds = int (m_islandmanifold.size());
//we should do radix sort, it it much faster (O(n) instead of O (n log2(n))
- islandmanifold.heapSort(btPersistentManifoldSortPredicate());
+ m_islandmanifold.heapSort(btPersistentManifoldSortPredicate());
//now process all active islands (sets of manifolds for now)
@@ -298,7 +297,7 @@ void btSimulationIslandManager::buildAndProcessIslands(btDispatcher* dispatcher, END_PROFILE("islandUnionFindAndHeapSort");
- btAlignedObjectArray<btCollisionObject*> islandBodies;
+
// printf("Start Islands\n");
@@ -314,7 +313,7 @@ void btSimulationIslandManager::buildAndProcessIslands(btDispatcher* dispatcher, {
int i = getUnionFind().getElement(endIslandIndex).m_sz;
btCollisionObject* colObj0 = collisionObjects[i];
- islandBodies.push_back(colObj0);
+ m_islandBodies.push_back(colObj0);
if (!colObj0->isActive())
islandSleeping = true;
}
@@ -326,12 +325,12 @@ void btSimulationIslandManager::buildAndProcessIslands(btDispatcher* dispatcher, if (startManifoldIndex<numManifolds)
{
- int curIslandId = getIslandId(islandmanifold[startManifoldIndex]);
+ int curIslandId = getIslandId(m_islandmanifold[startManifoldIndex]);
if (curIslandId == islandId)
{
- startManifold = &islandmanifold[startManifoldIndex];
+ startManifold = &m_islandmanifold[startManifoldIndex];
- for (endManifoldIndex = startManifoldIndex+1;(endManifoldIndex<numManifolds) && (islandId == getIslandId(islandmanifold[endManifoldIndex]));endManifoldIndex++)
+ for (endManifoldIndex = startManifoldIndex+1;(endManifoldIndex<numManifolds) && (islandId == getIslandId(m_islandmanifold[endManifoldIndex]));endManifoldIndex++)
{
}
@@ -343,7 +342,7 @@ void btSimulationIslandManager::buildAndProcessIslands(btDispatcher* dispatcher, if (!islandSleeping)
{
- callback->ProcessIsland(&islandBodies[0],islandBodies.size(),startManifold,numIslandManifolds, islandId);
+ callback->ProcessIsland(&m_islandBodies[0],m_islandBodies.size(),startManifold,numIslandManifolds, islandId);
// printf("Island callback of size:%d bodies, %d manifolds\n",islandBodies.size(),numIslandManifolds);
}
@@ -352,8 +351,9 @@ void btSimulationIslandManager::buildAndProcessIslands(btDispatcher* dispatcher, startManifoldIndex = endManifoldIndex;
}
- islandBodies.resize(0);
+ m_islandBodies.resize(0);
}
#endif //SPLIT_ISLANDS
-
+
+ m_islandmanifold.resize(0);
}
diff --git a/src/BulletCollision/CollisionDispatch/btSimulationIslandManager.h b/src/BulletCollision/CollisionDispatch/btSimulationIslandManager.h index da00f6fe2..0dffd3e2a 100644 --- a/src/BulletCollision/CollisionDispatch/btSimulationIslandManager.h +++ b/src/BulletCollision/CollisionDispatch/btSimulationIslandManager.h @@ -18,16 +18,24 @@ subject to the following restrictions: #include "BulletCollision/CollisionDispatch/btUnionFind.h" #include "btCollisionCreateFunc.h" +#include "LinearMath/btAlignedObjectArray.h" + class btCollisionObject; class btCollisionWorld; class btDispatcher; +class btPersistentManifold; + ///SimulationIslandManager creates and handles simulation islands, using btUnionFind class btSimulationIslandManager { btUnionFind m_unionFind; + btAlignedObjectArray<btPersistentManifold*> m_islandmanifold;
+ btAlignedObjectArray<btCollisionObject* > m_islandBodies;
+
+ public: btSimulationIslandManager(); virtual ~btSimulationIslandManager(); diff --git a/src/BulletCollision/CollisionShapes/btBvhTriangleMeshShape.cpp b/src/BulletCollision/CollisionShapes/btBvhTriangleMeshShape.cpp index 54af5c02a..6d9035a91 100644 --- a/src/BulletCollision/CollisionShapes/btBvhTriangleMeshShape.cpp +++ b/src/BulletCollision/CollisionShapes/btBvhTriangleMeshShape.cpp @@ -35,7 +35,8 @@ m_ownsBvh(false) if (buildBvh) { - m_bvh = new btOptimizedBvh(); + void* mem = btAlignedAlloc(sizeof(btOptimizedBvh),16); + m_bvh = new (mem) btOptimizedBvh(); m_bvh->build(meshInterface,m_useQuantizedAabbCompression,bvhAabbMin,bvhAabbMax); m_ownsBvh = true; } @@ -55,7 +56,9 @@ m_ownsBvh(false) if (buildBvh) { - m_bvh = new btOptimizedBvh(); + void* mem = btAlignedAlloc(sizeof(btOptimizedBvh),16); + m_bvh = new (mem) btOptimizedBvh(); + m_bvh->build(meshInterface,m_useQuantizedAabbCompression,bvhAabbMin,bvhAabbMax); m_ownsBvh = true; } @@ -83,7 +86,9 @@ void btBvhTriangleMeshShape::refitTree() btBvhTriangleMeshShape::~btBvhTriangleMeshShape() { if (m_ownsBvh) - delete m_bvh; + { + btAlignedFree(m_bvh); + } } //perform bvh tree traversal and report overlapping triangles to 'callback' @@ -180,9 +185,12 @@ void btBvhTriangleMeshShape::setLocalScaling(const btVector3& scaling) { btTriangleMeshShape::setLocalScaling(scaling); if (m_ownsBvh) - delete m_bvh; + { + btAlignedFree(m_bvh); + } ///m_localAabbMin/m_localAabbMax is already re-calculated in btTriangleMeshShape. We could just scale aabb, but this needs some more work - m_bvh = new btOptimizedBvh(); + void* mem = btAlignedAlloc(sizeof(btOptimizedBvh),16); + m_bvh = new(mem) btOptimizedBvh(); //rebuild the bvh... m_bvh->build(m_meshInterface,m_useQuantizedAabbCompression,m_localAabbMin,m_localAabbMax); |