- 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!
This commit is contained in:
@@ -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;
|
||||
|
||||
@@ -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;
|
||||
|
||||
}
|
||||
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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)
|
||||
|
||||
@@ -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)
|
||||
|
||||
@@ -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);
|
||||
|
||||
|
||||
}
|
||||
|
||||
@@ -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;
|
||||
|
||||
@@ -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);
|
||||
}
|
||||
|
||||
@@ -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();
|
||||
|
||||
@@ -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);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user