- removed warnings in GLUI, thanks Jorrit Tyberghein for the patch!
- removed memory leaks from BasicDemo and Bullet library (other demos needs to be cleaned up!) - added memory leak debugging functionality in btAlignedAlloc.h: #define BT_DEBUG_MEMORY_ALLOCATIONS
This commit is contained in:
@@ -288,6 +288,7 @@ btAxisSweep3Internal<BP_FP_INT_TYPE>::~btAxisSweep3Internal()
|
||||
|
||||
if (m_ownsPairCache)
|
||||
{
|
||||
m_pairCache->~btOverlappingPairCache();
|
||||
btAlignedFree(m_pairCache);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -124,30 +124,52 @@ btDefaultCollisionConfiguration::~btDefaultCollisionConfiguration()
|
||||
if (m_ownsStackAllocator)
|
||||
{
|
||||
m_stackAlloc->destroy();
|
||||
m_stackAlloc->~btStackAlloc();
|
||||
btAlignedFree(m_stackAlloc);
|
||||
}
|
||||
if (m_ownsCollisionAlgorithmPool)
|
||||
{
|
||||
m_collisionAlgorithmPool->~btPoolAllocator();
|
||||
btAlignedFree(m_collisionAlgorithmPool);
|
||||
}
|
||||
if (m_ownsPersistentManifoldPool)
|
||||
{
|
||||
m_persistentManifoldPool->~btPoolAllocator();
|
||||
btAlignedFree(m_persistentManifoldPool);
|
||||
}
|
||||
|
||||
m_convexConvexCreateFunc->~btCollisionAlgorithmCreateFunc();
|
||||
btAlignedFree( m_convexConvexCreateFunc);
|
||||
|
||||
m_convexConcaveCreateFunc->~btCollisionAlgorithmCreateFunc();
|
||||
btAlignedFree( m_convexConcaveCreateFunc);
|
||||
m_swappedConvexConcaveCreateFunc->~btCollisionAlgorithmCreateFunc();
|
||||
btAlignedFree( m_swappedConvexConcaveCreateFunc);
|
||||
|
||||
m_compoundCreateFunc->~btCollisionAlgorithmCreateFunc();
|
||||
btAlignedFree( m_compoundCreateFunc);
|
||||
|
||||
m_swappedCompoundCreateFunc->~btCollisionAlgorithmCreateFunc();
|
||||
btAlignedFree( m_swappedCompoundCreateFunc);
|
||||
|
||||
m_emptyCreateFunc->~btCollisionAlgorithmCreateFunc();
|
||||
btAlignedFree( m_emptyCreateFunc);
|
||||
|
||||
m_sphereSphereCF->~btCollisionAlgorithmCreateFunc();
|
||||
btAlignedFree( m_sphereSphereCF);
|
||||
|
||||
m_sphereBoxCF->~btCollisionAlgorithmCreateFunc();
|
||||
btAlignedFree( m_sphereBoxCF);
|
||||
m_boxSphereCF->~btCollisionAlgorithmCreateFunc();
|
||||
btAlignedFree( m_boxSphereCF);
|
||||
m_sphereTriangleCF->~btCollisionAlgorithmCreateFunc();
|
||||
btAlignedFree( m_sphereTriangleCF);
|
||||
m_triangleSphereCF->~btCollisionAlgorithmCreateFunc();
|
||||
btAlignedFree( m_triangleSphereCF);
|
||||
|
||||
m_simplexSolver->~btVoronoiSimplexSolver();
|
||||
btAlignedFree(m_simplexSolver);
|
||||
m_pdSolver->~btGjkEpaPenetrationDepthSolver();
|
||||
btAlignedFree(m_pdSolver);
|
||||
|
||||
|
||||
|
||||
@@ -124,6 +124,10 @@ m_btSeed2(0)
|
||||
}
|
||||
}
|
||||
|
||||
btSequentialImpulseConstraintSolver::~btSequentialImpulseConstraintSolver()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
void initSolverBody(btSolverBody* solverBody, btRigidBody* rigidbody)
|
||||
{
|
||||
@@ -360,18 +364,14 @@ btScalar resolveSingleFrictionCacheFriendly(
|
||||
|
||||
#endif //NO_FRICTION_TANGENTIALS
|
||||
|
||||
btAlignedObjectArray<btSolverBody> tmpSolverBodyPool;
|
||||
btAlignedObjectArray<btSolverConstraint> tmpSolverConstraintPool;
|
||||
btAlignedObjectArray<btSolverConstraint> tmpSolverFrictionConstraintPool;
|
||||
btAlignedObjectArray<int> gOrderTmpConstraintPool;
|
||||
btAlignedObjectArray<int> gOrderFrictionConstraintPool;
|
||||
|
||||
|
||||
|
||||
void addFrictionConstraint(const btVector3& normalAxis,int solverBodyIdA,int solverBodyIdB,int frictionIndex,btManifoldPoint& cp,const btVector3& rel_pos1,const btVector3& rel_pos2,btRigidBody* rb0,btRigidBody* rb1, btScalar relaxation)
|
||||
|
||||
void btSequentialImpulseConstraintSolver::addFrictionConstraint(const btVector3& normalAxis,int solverBodyIdA,int solverBodyIdB,int frictionIndex,btManifoldPoint& cp,const btVector3& rel_pos1,const btVector3& rel_pos2,btRigidBody* rb0,btRigidBody* rb1, btScalar relaxation)
|
||||
{
|
||||
|
||||
btSolverConstraint& solverConstraint = tmpSolverFrictionConstraintPool.expand();
|
||||
btSolverConstraint& solverConstraint = m_tmpSolverFrictionConstraintPool.expand();
|
||||
solverConstraint.m_contactNormal = normalAxis;
|
||||
|
||||
solverConstraint.m_solverBodyIdA = solverBodyIdA;
|
||||
@@ -469,7 +469,7 @@ btScalar btSequentialImpulseConstraintSolver::solveGroupCacheFriendlySetup(btCol
|
||||
//todo: use stack allocator for this temp memory
|
||||
int minReservation = numManifolds*2;
|
||||
|
||||
//tmpSolverBodyPool.reserve(minReservation);
|
||||
//m_tmpSolverBodyPool.reserve(minReservation);
|
||||
|
||||
//don't convert all bodies, only the one we need so solver the constraints
|
||||
/*
|
||||
@@ -480,8 +480,8 @@ btScalar btSequentialImpulseConstraintSolver::solveGroupCacheFriendlySetup(btCol
|
||||
if (rb && (rb->getIslandTag() >= 0))
|
||||
{
|
||||
btAssert(rb->getCompanionId() < 0);
|
||||
int solverBodyId = tmpSolverBodyPool.size();
|
||||
btSolverBody& solverBody = tmpSolverBodyPool.expand();
|
||||
int solverBodyId = m_tmpSolverBodyPool.size();
|
||||
btSolverBody& solverBody = m_tmpSolverBodyPool.expand();
|
||||
initSolverBody(&solverBody,rb);
|
||||
rb->setCompanionId(solverBodyId);
|
||||
}
|
||||
@@ -489,8 +489,8 @@ btScalar btSequentialImpulseConstraintSolver::solveGroupCacheFriendlySetup(btCol
|
||||
}
|
||||
*/
|
||||
|
||||
//tmpSolverConstraintPool.reserve(minReservation);
|
||||
//tmpSolverFrictionConstraintPool.reserve(minReservation);
|
||||
//m_tmpSolverConstraintPool.reserve(minReservation);
|
||||
//m_tmpSolverFrictionConstraintPool.reserve(minReservation);
|
||||
|
||||
{
|
||||
int i;
|
||||
@@ -519,16 +519,16 @@ btScalar btSequentialImpulseConstraintSolver::solveGroupCacheFriendlySetup(btCol
|
||||
solverBodyIdA = rb0->getCompanionId();
|
||||
} else
|
||||
{
|
||||
solverBodyIdA = tmpSolverBodyPool.size();
|
||||
btSolverBody& solverBody = tmpSolverBodyPool.expand();
|
||||
solverBodyIdA = m_tmpSolverBodyPool.size();
|
||||
btSolverBody& solverBody = m_tmpSolverBodyPool.expand();
|
||||
initSolverBody(&solverBody,rb0);
|
||||
rb0->setCompanionId(solverBodyIdA);
|
||||
}
|
||||
} else
|
||||
{
|
||||
//create a static body
|
||||
solverBodyIdA = tmpSolverBodyPool.size();
|
||||
btSolverBody& solverBody = tmpSolverBodyPool.expand();
|
||||
solverBodyIdA = m_tmpSolverBodyPool.size();
|
||||
btSolverBody& solverBody = m_tmpSolverBodyPool.expand();
|
||||
initSolverBody(&solverBody,rb0);
|
||||
}
|
||||
|
||||
@@ -539,16 +539,16 @@ btScalar btSequentialImpulseConstraintSolver::solveGroupCacheFriendlySetup(btCol
|
||||
solverBodyIdB = rb1->getCompanionId();
|
||||
} else
|
||||
{
|
||||
solverBodyIdB = tmpSolverBodyPool.size();
|
||||
btSolverBody& solverBody = tmpSolverBodyPool.expand();
|
||||
solverBodyIdB = m_tmpSolverBodyPool.size();
|
||||
btSolverBody& solverBody = m_tmpSolverBodyPool.expand();
|
||||
initSolverBody(&solverBody,rb1);
|
||||
rb1->setCompanionId(solverBodyIdB);
|
||||
}
|
||||
} else
|
||||
{
|
||||
//create a static body
|
||||
solverBodyIdB = tmpSolverBodyPool.size();
|
||||
btSolverBody& solverBody = tmpSolverBodyPool.expand();
|
||||
solverBodyIdB = m_tmpSolverBodyPool.size();
|
||||
btSolverBody& solverBody = m_tmpSolverBodyPool.expand();
|
||||
initSolverBody(&solverBody,rb1);
|
||||
}
|
||||
}
|
||||
@@ -580,10 +580,10 @@ btScalar btSequentialImpulseConstraintSolver::solveGroupCacheFriendlySetup(btCol
|
||||
btScalar rel_vel;
|
||||
btVector3 vel;
|
||||
|
||||
int frictionIndex = tmpSolverConstraintPool.size();
|
||||
int frictionIndex = m_tmpSolverConstraintPool.size();
|
||||
|
||||
{
|
||||
btSolverConstraint& solverConstraint = tmpSolverConstraintPool.expand();
|
||||
btSolverConstraint& solverConstraint = m_tmpSolverConstraintPool.expand();
|
||||
|
||||
solverConstraint.m_solverBodyIdA = solverBodyIdA;
|
||||
solverConstraint.m_solverBodyIdB = solverBodyIdB;
|
||||
@@ -690,21 +690,21 @@ btScalar btSequentialImpulseConstraintSolver::solveGroupCacheFriendlySetup(btCol
|
||||
|
||||
|
||||
|
||||
int numConstraintPool = tmpSolverConstraintPool.size();
|
||||
int numFrictionPool = tmpSolverFrictionConstraintPool.size();
|
||||
int numConstraintPool = m_tmpSolverConstraintPool.size();
|
||||
int numFrictionPool = m_tmpSolverFrictionConstraintPool.size();
|
||||
|
||||
///todo: use stack allocator for such temporarily memory, same for solver bodies/constraints
|
||||
gOrderTmpConstraintPool.resize(numConstraintPool);
|
||||
gOrderFrictionConstraintPool.resize(numFrictionPool);
|
||||
m_orderTmpConstraintPool.resize(numConstraintPool);
|
||||
m_orderFrictionConstraintPool.resize(numFrictionPool);
|
||||
{
|
||||
int i;
|
||||
for (i=0;i<numConstraintPool;i++)
|
||||
{
|
||||
gOrderTmpConstraintPool[i] = i;
|
||||
m_orderTmpConstraintPool[i] = i;
|
||||
}
|
||||
for (i=0;i<numFrictionPool;i++)
|
||||
{
|
||||
gOrderFrictionConstraintPool[i] = i;
|
||||
m_orderFrictionConstraintPool[i] = i;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -719,8 +719,8 @@ btScalar btSequentialImpulseConstraintSolver::solveGroupCacheFriendlySetup(btCol
|
||||
btScalar btSequentialImpulseConstraintSolver::solveGroupCacheFriendlyIterations(btCollisionObject** bodies,int numBodies,btPersistentManifold** manifoldPtr, int numManifolds,btTypedConstraint** constraints,int numConstraints,const btContactSolverInfo& infoGlobal,btIDebugDraw* debugDrawer,btStackAlloc* stackAlloc)
|
||||
{
|
||||
BEGIN_PROFILE("solveConstraintsIterations");
|
||||
int numConstraintPool = tmpSolverConstraintPool.size();
|
||||
int numFrictionPool = tmpSolverFrictionConstraintPool.size();
|
||||
int numConstraintPool = m_tmpSolverConstraintPool.size();
|
||||
int numFrictionPool = m_tmpSolverFrictionConstraintPool.size();
|
||||
|
||||
//should traverse the contacts random order...
|
||||
int iteration;
|
||||
@@ -733,17 +733,17 @@ btScalar btSequentialImpulseConstraintSolver::solveGroupCacheFriendlyIterations(
|
||||
{
|
||||
if ((iteration & 7) == 0) {
|
||||
for (j=0; j<numConstraintPool; ++j) {
|
||||
int tmp = gOrderTmpConstraintPool[j];
|
||||
int tmp = m_orderTmpConstraintPool[j];
|
||||
int swapi = btRandInt2(j+1);
|
||||
gOrderTmpConstraintPool[j] = gOrderTmpConstraintPool[swapi];
|
||||
gOrderTmpConstraintPool[swapi] = tmp;
|
||||
m_orderTmpConstraintPool[j] = m_orderTmpConstraintPool[swapi];
|
||||
m_orderTmpConstraintPool[swapi] = tmp;
|
||||
}
|
||||
|
||||
for (j=0; j<numFrictionPool; ++j) {
|
||||
int tmp = gOrderFrictionConstraintPool[j];
|
||||
int tmp = m_orderFrictionConstraintPool[j];
|
||||
int swapi = btRandInt2(j+1);
|
||||
gOrderFrictionConstraintPool[j] = gOrderFrictionConstraintPool[swapi];
|
||||
gOrderFrictionConstraintPool[swapi] = tmp;
|
||||
m_orderFrictionConstraintPool[j] = m_orderFrictionConstraintPool[swapi];
|
||||
m_orderFrictionConstraintPool[swapi] = tmp;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -755,47 +755,47 @@ btScalar btSequentialImpulseConstraintSolver::solveGroupCacheFriendlyIterations(
|
||||
|
||||
if ((constraint->getRigidBodyA().getIslandTag() >= 0) && (constraint->getRigidBodyA().getCompanionId() >= 0))
|
||||
{
|
||||
tmpSolverBodyPool[constraint->getRigidBodyA().getCompanionId()].writebackVelocity();
|
||||
m_tmpSolverBodyPool[constraint->getRigidBodyA().getCompanionId()].writebackVelocity();
|
||||
}
|
||||
if ((constraint->getRigidBodyB().getIslandTag() >= 0) && (constraint->getRigidBodyB().getCompanionId() >= 0))
|
||||
{
|
||||
tmpSolverBodyPool[constraint->getRigidBodyB().getCompanionId()].writebackVelocity();
|
||||
m_tmpSolverBodyPool[constraint->getRigidBodyB().getCompanionId()].writebackVelocity();
|
||||
}
|
||||
|
||||
constraint->solveConstraint(infoGlobal.m_timeStep);
|
||||
|
||||
if ((constraint->getRigidBodyA().getIslandTag() >= 0) && (constraint->getRigidBodyA().getCompanionId() >= 0))
|
||||
{
|
||||
tmpSolverBodyPool[constraint->getRigidBodyA().getCompanionId()].readVelocity();
|
||||
m_tmpSolverBodyPool[constraint->getRigidBodyA().getCompanionId()].readVelocity();
|
||||
}
|
||||
if ((constraint->getRigidBodyB().getIslandTag() >= 0) && (constraint->getRigidBodyB().getCompanionId() >= 0))
|
||||
{
|
||||
tmpSolverBodyPool[constraint->getRigidBodyB().getCompanionId()].readVelocity();
|
||||
m_tmpSolverBodyPool[constraint->getRigidBodyB().getCompanionId()].readVelocity();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
{
|
||||
int numPoolConstraints = tmpSolverConstraintPool.size();
|
||||
int numPoolConstraints = m_tmpSolverConstraintPool.size();
|
||||
for (j=0;j<numPoolConstraints;j++)
|
||||
{
|
||||
const btSolverConstraint& solveManifold = tmpSolverConstraintPool[gOrderTmpConstraintPool[j]];
|
||||
resolveSingleCollisionCombinedCacheFriendly(tmpSolverBodyPool[solveManifold.m_solverBodyIdA],
|
||||
tmpSolverBodyPool[solveManifold.m_solverBodyIdB],solveManifold,infoGlobal);
|
||||
const btSolverConstraint& solveManifold = m_tmpSolverConstraintPool[m_orderTmpConstraintPool[j]];
|
||||
resolveSingleCollisionCombinedCacheFriendly(m_tmpSolverBodyPool[solveManifold.m_solverBodyIdA],
|
||||
m_tmpSolverBodyPool[solveManifold.m_solverBodyIdB],solveManifold,infoGlobal);
|
||||
}
|
||||
}
|
||||
|
||||
{
|
||||
int numFrictionPoolConstraints = tmpSolverFrictionConstraintPool.size();
|
||||
int numFrictionPoolConstraints = m_tmpSolverFrictionConstraintPool.size();
|
||||
|
||||
for (j=0;j<numFrictionPoolConstraints;j++)
|
||||
{
|
||||
const btSolverConstraint& solveManifold = tmpSolverFrictionConstraintPool[gOrderFrictionConstraintPool[j]];
|
||||
const btSolverConstraint& solveManifold = m_tmpSolverFrictionConstraintPool[m_orderFrictionConstraintPool[j]];
|
||||
|
||||
|
||||
resolveSingleFrictionCacheFriendly(tmpSolverBodyPool[solveManifold.m_solverBodyIdA],
|
||||
tmpSolverBodyPool[solveManifold.m_solverBodyIdB],solveManifold,infoGlobal,
|
||||
tmpSolverConstraintPool[solveManifold.m_frictionIndex].m_appliedImpulse);
|
||||
resolveSingleFrictionCacheFriendly(m_tmpSolverBodyPool[solveManifold.m_solverBodyIdA],
|
||||
m_tmpSolverBodyPool[solveManifold.m_solverBodyIdB],solveManifold,infoGlobal,
|
||||
m_tmpSolverConstraintPool[solveManifold.m_frictionIndex].m_appliedImpulse);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -819,29 +819,29 @@ btScalar btSequentialImpulseConstraintSolver::solveGroupCacheFriendly(btCollisio
|
||||
|
||||
BEGIN_PROFILE("solveWriteBackVelocity");
|
||||
|
||||
for ( i=0;i<tmpSolverBodyPool.size();i++)
|
||||
for ( i=0;i<m_tmpSolverBodyPool.size();i++)
|
||||
{
|
||||
tmpSolverBodyPool[i].writebackVelocity();
|
||||
m_tmpSolverBodyPool[i].writebackVelocity();
|
||||
}
|
||||
|
||||
END_PROFILE("solveWriteBackVelocity");
|
||||
|
||||
// printf("tmpSolverConstraintPool.size() = %i\n",tmpSolverConstraintPool.size());
|
||||
// printf("m_tmpSolverConstraintPool.size() = %i\n",m_tmpSolverConstraintPool.size());
|
||||
|
||||
/*
|
||||
printf("tmpSolverBodyPool.size() = %i\n",tmpSolverBodyPool.size());
|
||||
printf("tmpSolverConstraintPool.size() = %i\n",tmpSolverConstraintPool.size());
|
||||
printf("tmpSolverFrictionConstraintPool.size() = %i\n",tmpSolverFrictionConstraintPool.size());
|
||||
printf("m_tmpSolverBodyPool.size() = %i\n",m_tmpSolverBodyPool.size());
|
||||
printf("m_tmpSolverConstraintPool.size() = %i\n",m_tmpSolverConstraintPool.size());
|
||||
printf("m_tmpSolverFrictionConstraintPool.size() = %i\n",m_tmpSolverFrictionConstraintPool.size());
|
||||
|
||||
|
||||
printf("tmpSolverBodyPool.capacity() = %i\n",tmpSolverBodyPool.capacity());
|
||||
printf("tmpSolverConstraintPool.capacity() = %i\n",tmpSolverConstraintPool.capacity());
|
||||
printf("tmpSolverFrictionConstraintPool.capacity() = %i\n",tmpSolverFrictionConstraintPool.capacity());
|
||||
printf("m_tmpSolverBodyPool.capacity() = %i\n",m_tmpSolverBodyPool.capacity());
|
||||
printf("m_tmpSolverConstraintPool.capacity() = %i\n",m_tmpSolverConstraintPool.capacity());
|
||||
printf("m_tmpSolverFrictionConstraintPool.capacity() = %i\n",m_tmpSolverFrictionConstraintPool.capacity());
|
||||
*/
|
||||
|
||||
tmpSolverBodyPool.resize(0);
|
||||
tmpSolverConstraintPool.resize(0);
|
||||
tmpSolverFrictionConstraintPool.resize(0);
|
||||
m_tmpSolverBodyPool.resize(0);
|
||||
m_tmpSolverConstraintPool.resize(0);
|
||||
m_tmpSolverFrictionConstraintPool.resize(0);
|
||||
|
||||
|
||||
return 0.f;
|
||||
|
||||
@@ -19,7 +19,8 @@ subject to the following restrictions:
|
||||
#include "btConstraintSolver.h"
|
||||
class btIDebugDraw;
|
||||
#include "btContactConstraint.h"
|
||||
|
||||
#include "btSolverBody.h"
|
||||
#include "btSolverConstraint.h"
|
||||
|
||||
|
||||
/// btSequentialImpulseConstraintSolver uses a Propagation Method and Sequentially applies impulses
|
||||
@@ -29,10 +30,18 @@ class btIDebugDraw;
|
||||
class btSequentialImpulseConstraintSolver : public btConstraintSolver
|
||||
{
|
||||
|
||||
btAlignedObjectArray<btSolverBody> m_tmpSolverBodyPool;
|
||||
btAlignedObjectArray<btSolverConstraint> m_tmpSolverConstraintPool;
|
||||
btAlignedObjectArray<btSolverConstraint> m_tmpSolverFrictionConstraintPool;
|
||||
btAlignedObjectArray<int> m_orderTmpConstraintPool;
|
||||
btAlignedObjectArray<int> m_orderFrictionConstraintPool;
|
||||
|
||||
|
||||
protected:
|
||||
btScalar solve(btRigidBody* body0,btRigidBody* body1, btManifoldPoint& cp, const btContactSolverInfo& info,int iter,btIDebugDraw* debugDrawer);
|
||||
btScalar solveFriction(btRigidBody* body0,btRigidBody* body1, btManifoldPoint& cp, const btContactSolverInfo& info,int iter,btIDebugDraw* debugDrawer);
|
||||
void prepareConstraints(btPersistentManifold* manifoldPtr, const btContactSolverInfo& info,btIDebugDraw* debugDrawer);
|
||||
void addFrictionConstraint(const btVector3& normalAxis,int solverBodyIdA,int solverBodyIdB,int frictionIndex,btManifoldPoint& cp,const btVector3& rel_pos1,const btVector3& rel_pos2,btRigidBody* rb0,btRigidBody* rb1, btScalar relaxation);
|
||||
|
||||
ContactSolverFunc m_contactDispatch[MAX_CONTACT_SOLVER_TYPES][MAX_CONTACT_SOLVER_TYPES];
|
||||
ContactSolverFunc m_frictionDispatch[MAX_CONTACT_SOLVER_TYPES][MAX_CONTACT_SOLVER_TYPES];
|
||||
@@ -68,7 +77,7 @@ public:
|
||||
m_frictionDispatch[type0][type1] = func;
|
||||
}
|
||||
|
||||
virtual ~btSequentialImpulseConstraintSolver() {}
|
||||
virtual ~btSequentialImpulseConstraintSolver();
|
||||
|
||||
virtual btScalar solveGroup(btCollisionObject** bodies,int numBodies,btPersistentManifold** manifold,int numManifolds,btTypedConstraint** constraints,int numConstraints,const btContactSolverInfo& info, btIDebugDraw* debugDrawer, btStackAlloc* stackAlloc,btDispatcher* dispatcher);
|
||||
|
||||
|
||||
@@ -65,7 +65,7 @@ m_gravity(0,-10,0),
|
||||
m_localTime(btScalar(1.)/btScalar(60.)),
|
||||
m_profileTimings(0)
|
||||
{
|
||||
if (m_constraintSolver)
|
||||
if (!m_constraintSolver)
|
||||
{
|
||||
void* mem = btAlignedAlloc(sizeof(btSequentialImpulseConstraintSolver),16);
|
||||
m_constraintSolver = new (mem) btSequentialImpulseConstraintSolver;
|
||||
@@ -88,9 +88,16 @@ btDiscreteDynamicsWorld::~btDiscreteDynamicsWorld()
|
||||
{
|
||||
//only delete it when we created it
|
||||
if (m_ownsIslandManager)
|
||||
{
|
||||
m_islandManager->~btSimulationIslandManager();
|
||||
btAlignedFree( m_islandManager);
|
||||
}
|
||||
if (m_ownsConstraintSolver)
|
||||
btAlignedFree(m_constraintSolver);
|
||||
{
|
||||
|
||||
m_constraintSolver->~btConstraintSolver();
|
||||
btAlignedFree(m_constraintSolver);
|
||||
}
|
||||
}
|
||||
|
||||
void btDiscreteDynamicsWorld::saveKinematicState(btScalar timeStep)
|
||||
|
||||
@@ -17,6 +17,60 @@ subject to the following restrictions:
|
||||
|
||||
int gNumAlignedAllocs = 0;
|
||||
int gNumAlignedFree = 0;
|
||||
int gTotalBytesAlignedAllocs = 0;//detect memory leaks
|
||||
|
||||
#ifdef BT_DEBUG_MEMORY_ALLOCATIONS
|
||||
//this generic allocator provides the total allocated number of bytes
|
||||
#include <stdio.h>
|
||||
|
||||
void* btAlignedAllocInternal (size_t size, int alignment,int line,char* filename)
|
||||
{
|
||||
void *ret;
|
||||
char *real;
|
||||
unsigned long offset;
|
||||
|
||||
gTotalBytesAlignedAllocs += size;
|
||||
gNumAlignedAllocs++;
|
||||
|
||||
printf("allocation#%d from %s,line %d, size %d\n",gNumAlignedAllocs,filename,line,size);
|
||||
real = (char *)malloc(size + 2*sizeof(void *) + (alignment-1));
|
||||
if (real) {
|
||||
offset = (alignment - (unsigned long)(real + 2*sizeof(void *))) &
|
||||
(alignment-1);
|
||||
ret = (void *)((real + 2*sizeof(void *)) + offset);
|
||||
*((void **)(ret)-1) = (void *)(real);
|
||||
*((int*)(ret)-2) = size;
|
||||
|
||||
} else {
|
||||
ret = (void *)(real);//??
|
||||
}
|
||||
int* ptr = (int*)ret;
|
||||
*ptr = 12;
|
||||
return (ret);
|
||||
}
|
||||
#include <stdio.h>
|
||||
void btAlignedFreeInternal (void* ptr,int line,char* filename)
|
||||
{
|
||||
|
||||
void* real;
|
||||
gNumAlignedFree++;
|
||||
|
||||
if (ptr) {
|
||||
real = *((void **)(ptr)-1);
|
||||
int size = *((int*)(ptr)-2);
|
||||
gTotalBytesAlignedAllocs -= size;
|
||||
|
||||
printf("free #%d from %s,line %d, size %d\n",gNumAlignedFree,filename,line,size);
|
||||
|
||||
free(real);
|
||||
} else
|
||||
{
|
||||
printf("NULL ptr\n");
|
||||
}
|
||||
}
|
||||
|
||||
#else //BT_DEBUG_MEMORY_ALLOCATIONS
|
||||
|
||||
|
||||
#if defined (BT_HAS_ALIGNED_ALLOCATOR)
|
||||
|
||||
@@ -25,19 +79,19 @@ int gNumAlignedFree = 0;
|
||||
|
||||
|
||||
#include <malloc.h>
|
||||
void* btAlignedAlloc (size_t size, int alignment)
|
||||
void* btAlignedAllocInternal (size_t size, int alignment)
|
||||
{
|
||||
gNumAlignedAllocs++;
|
||||
|
||||
void* ptr = _aligned_malloc(size,alignment);
|
||||
// printf("btAlignedAlloc %d, %x\n",size,ptr);
|
||||
// printf("btAlignedAllocInternal %d, %x\n",size,ptr);
|
||||
return ptr;
|
||||
}
|
||||
|
||||
void btAlignedFree (void* ptr)
|
||||
void btAlignedFreeInternal (void* ptr)
|
||||
{
|
||||
gNumAlignedFree++;
|
||||
// printf("btAlignedFree %x\n",ptr);
|
||||
// printf("btAlignedFreeInternal %x\n",ptr);
|
||||
_aligned_free(ptr);
|
||||
}
|
||||
|
||||
@@ -49,13 +103,13 @@ void btAlignedFree (void* ptr)
|
||||
|
||||
|
||||
|
||||
void* btAlignedAlloc (size_t size, int alignment)
|
||||
void* btAlignedAllocInternal (size_t size, int alignment)
|
||||
{
|
||||
gNumAlignedAllocs++;
|
||||
return memalign(alignment, size);
|
||||
}
|
||||
|
||||
void btAlignedFree (void* ptr)
|
||||
void btAlignedFreeInternal (void* ptr)
|
||||
{
|
||||
gNumAlignedFree++;
|
||||
free(ptr);
|
||||
@@ -63,7 +117,7 @@ void btAlignedFree (void* ptr)
|
||||
|
||||
#else
|
||||
|
||||
void* btAlignedAlloc (size_t size, int alignment)
|
||||
void* btAlignedAllocInternal (size_t size, int alignment)
|
||||
{
|
||||
void *ret;
|
||||
char *real;
|
||||
@@ -82,7 +136,7 @@ void* btAlignedAlloc (size_t size, int alignment)
|
||||
return (ret);
|
||||
}
|
||||
|
||||
void btAlignedFree (void* ptr)
|
||||
void btAlignedFreeInternal (void* ptr)
|
||||
{
|
||||
|
||||
void* real;
|
||||
@@ -97,4 +151,5 @@ void btAlignedFree (void* ptr)
|
||||
|
||||
#endif
|
||||
|
||||
#endif //BT_DEBUG_MEMORY_ALLOCATIONS
|
||||
|
||||
|
||||
@@ -21,12 +21,26 @@ subject to the following restrictions:
|
||||
///that is better portable and more predictable
|
||||
|
||||
#include "btScalar.h"
|
||||
//#define BT_DEBUG_MEMORY_ALLOCATIONS 1
|
||||
#ifdef BT_DEBUG_MEMORY_ALLOCATIONS
|
||||
|
||||
void* btAlignedAlloc (size_t size, int alignment);
|
||||
#define btAlignedAlloc(a,b) \
|
||||
btAlignedAllocInternal(a,b,__LINE__,__FILE__)
|
||||
|
||||
void btAlignedFree (void* ptr);
|
||||
#define btAlignedFree(ptr) \
|
||||
btAlignedFreeInternal(ptr,__LINE__,__FILE__)
|
||||
|
||||
void* btAlignedAllocInternal (size_t size, int alignment,int line,char* filename);
|
||||
|
||||
void btAlignedFreeInternal (void* ptr,int line,char* filename);
|
||||
|
||||
#else
|
||||
void* btAlignedAllocInternal (size_t size, int alignment);
|
||||
void btAlignedFreeInternal (void* ptr);
|
||||
|
||||
#define btAlignedAlloc(a,b) btAlignedAllocInternal(a,b)
|
||||
#define btAlignedFree(ptr) btAlignedFreeInternal(ptr)
|
||||
#endif
|
||||
typedef int size_type;
|
||||
|
||||
|
||||
|
||||
@@ -50,7 +50,7 @@ public:
|
||||
|
||||
if(usedsize==0)
|
||||
{
|
||||
if(!ischild)
|
||||
if(!ischild && data)
|
||||
btAlignedFree(data);
|
||||
|
||||
data = 0;
|
||||
|
||||
Reference in New Issue
Block a user