From f2afb4af35cf849b632c95b06f718799cbab3ee7 Mon Sep 17 00:00:00 2001 From: Jeffrey Bingham Date: Sat, 23 Jun 2018 21:41:24 -0700 Subject: [PATCH] remove some debug globals from third_party/bullet There are some debug global variables that prevent using bullet safely on multi-threaded environments (tsan failures). PATCH from marioprats@ --- examples/SoftDemo/SoftDemo.cpp | 11 -------- .../btAxisSweep3Internal.h | 8 +++--- .../btOverlappingPairCache.cpp | 27 +++++-------------- .../btOverlappingPairCache.h | 6 ----- .../btSimpleBroadphase.cpp | 5 +--- .../btCollisionDispatcher.cpp | 5 ---- src/LinearMath/btAlignedAllocator.cpp | 16 ----------- 7 files changed, 10 insertions(+), 68 deletions(-) diff --git a/examples/SoftDemo/SoftDemo.cpp b/examples/SoftDemo/SoftDemo.cpp index 9b09adafe..e12906d7d 100644 --- a/examples/SoftDemo/SoftDemo.cpp +++ b/examples/SoftDemo/SoftDemo.cpp @@ -291,10 +291,6 @@ void SoftDemo::createStack( btCollisionShape* boxShape, float halfCubeSize, int //////////////////////////////////// - -extern int gNumManifold; -extern int gOverlappingPairs; - ///for mouse picking void pickingPreTickCallback (btDynamicsWorld *world, btScalar timeStep) { @@ -1727,13 +1723,6 @@ void SoftDemo::clientMoveAndDisplay() btProfiler::endBlock("render"); #endif glFlush(); - //some additional debugging info -#ifdef PRINT_CONTACT_STATISTICS - printf("num manifolds: %i\n",gNumManifold); - printf("num gOverlappingPairs: %i\n",gOverlappingPairs); - -#endif //PRINT_CONTACT_STATISTICS - swapBuffers(); diff --git a/src/BulletCollision/BroadphaseCollision/btAxisSweep3Internal.h b/src/BulletCollision/BroadphaseCollision/btAxisSweep3Internal.h index 2c4d41bc0..323aa96dc 100644 --- a/src/BulletCollision/BroadphaseCollision/btAxisSweep3Internal.h +++ b/src/BulletCollision/BroadphaseCollision/btAxisSweep3Internal.h @@ -628,7 +628,6 @@ void btAxisSweep3Internal::resetPool(btDispatcher* /*dispatcher* } -extern int gOverlappingPairs; //#include template @@ -695,10 +694,9 @@ void btAxisSweep3Internal::calculateOverlappingPairs(btDispatche pair.m_pProxy0 = 0; pair.m_pProxy1 = 0; m_invalidPair++; - gOverlappingPairs--; - } - - } + } + + } ///if you don't like to skip the invalid pairs in the array, execute following code: #define CLEAN_INVALID_PAIRS 1 diff --git a/src/BulletCollision/BroadphaseCollision/btOverlappingPairCache.cpp b/src/BulletCollision/BroadphaseCollision/btOverlappingPairCache.cpp index da1335702..9e3337c5f 100644 --- a/src/BulletCollision/BroadphaseCollision/btOverlappingPairCache.cpp +++ b/src/BulletCollision/BroadphaseCollision/btOverlappingPairCache.cpp @@ -23,11 +23,6 @@ subject to the following restrictions: #include -int gOverlappingPairs = 0; - -int gRemovePairs =0; -int gAddedPairs =0; -int gFindPairs =0; @@ -134,13 +129,12 @@ void btHashedOverlappingPairCache::removeOverlappingPairsContainingProxy(btBroad btBroadphasePair* btHashedOverlappingPairCache::findPair(btBroadphaseProxy* proxy0, btBroadphaseProxy* proxy1) { - gFindPairs++; - if(proxy0->m_uniqueId>proxy1->m_uniqueId) + if(proxy0->m_uniqueId>proxy1->m_uniqueId) btSwap(proxy0,proxy1); int proxyId1 = proxy0->getUid(); int proxyId2 = proxy1->getUid(); - /*if (proxyId1 > proxyId2) + /*if (proxyId1 > proxyId2) btSwap(proxyId1, proxyId2);*/ int hash = static_cast(getHash(static_cast(proxyId1), static_cast(proxyId2)) & (m_overlappingPairArray.capacity()-1)); @@ -271,13 +265,12 @@ btBroadphasePair* btHashedOverlappingPairCache::internalAddPair(btBroadphaseProx void* btHashedOverlappingPairCache::removeOverlappingPair(btBroadphaseProxy* proxy0, btBroadphaseProxy* proxy1,btDispatcher* dispatcher) { - gRemovePairs++; - if(proxy0->m_uniqueId>proxy1->m_uniqueId) + if(proxy0->m_uniqueId>proxy1->m_uniqueId) btSwap(proxy0,proxy1); int proxyId1 = proxy0->getUid(); int proxyId2 = proxy1->getUid(); - /*if (proxyId1 > proxyId2) + /*if (proxyId1 > proxyId2) btSwap(proxyId1, proxyId2);*/ int hash = static_cast(getHash(static_cast(proxyId1),static_cast(proxyId2)) & (m_overlappingPairArray.capacity()-1)); @@ -386,8 +379,6 @@ void btHashedOverlappingPairCache::processAllOverlappingPairs(btOverlapCallback* if (callback->processOverlap(*pair)) { removeOverlappingPair(pair->m_pProxy0,pair->m_pProxy1,dispatcher); - - gOverlappingPairs--; } else { i++; @@ -499,7 +490,6 @@ void* btSortedOverlappingPairCache::removeOverlappingPair(btBroadphaseProxy* pro int findIndex = m_overlappingPairArray.findLinearSearch(findPair); if (findIndex < m_overlappingPairArray.size()) { - gOverlappingPairs--; btBroadphasePair& pair = m_overlappingPairArray[findIndex]; void* userData = pair.m_internalInfo1; cleanOverlappingPair(pair,dispatcher); @@ -532,11 +522,8 @@ btBroadphasePair* btSortedOverlappingPairCache::addOverlappingPair(btBroadphaseP void* mem = &m_overlappingPairArray.expandNonInitializing(); btBroadphasePair* pair = new (mem) btBroadphasePair(*proxy0,*proxy1); - - gOverlappingPairs++; - gAddedPairs++; - - if (m_ghostPairCallback) + + if (m_ghostPairCallback) m_ghostPairCallback->addOverlappingPair(proxy0, proxy1); return pair; @@ -590,7 +577,6 @@ void btSortedOverlappingPairCache::processAllOverlappingPairs(btOverlapCallback* pair->m_pProxy1 = 0; m_overlappingPairArray.swap(i,m_overlappingPairArray.size()-1); m_overlappingPairArray.pop_back(); - gOverlappingPairs--; } else { i++; @@ -623,7 +609,6 @@ void btSortedOverlappingPairCache::cleanOverlappingPair(btBroadphasePair& pair,b pair.m_algorithm->~btCollisionAlgorithm(); dispatcher->freeCollisionAlgorithm(pair.m_algorithm); pair.m_algorithm=0; - gRemovePairs--; } } } diff --git a/src/BulletCollision/BroadphaseCollision/btOverlappingPairCache.h b/src/BulletCollision/BroadphaseCollision/btOverlappingPairCache.h index 2551ac0e5..7a38d34f0 100644 --- a/src/BulletCollision/BroadphaseCollision/btOverlappingPairCache.h +++ b/src/BulletCollision/BroadphaseCollision/btOverlappingPairCache.h @@ -49,10 +49,6 @@ struct btOverlapFilterCallback -extern int gRemovePairs; -extern int gAddedPairs; -extern int gFindPairs; - const int BT_NULL_PAIR=0xffffffff; ///The btOverlappingPairCache provides an interface for overlapping pair management (add, remove, storage), used by the btBroadphaseInterface broadphases. @@ -133,8 +129,6 @@ public: // no new pair is created and the old one is returned. virtual btBroadphasePair* addOverlappingPair(btBroadphaseProxy* proxy0,btBroadphaseProxy* proxy1) { - gAddedPairs++; - if (!needsBroadphaseCollision(proxy0,proxy1)) return 0; diff --git a/src/BulletCollision/BroadphaseCollision/btSimpleBroadphase.cpp b/src/BulletCollision/BroadphaseCollision/btSimpleBroadphase.cpp index f1d5f5476..5f89f960e 100644 --- a/src/BulletCollision/BroadphaseCollision/btSimpleBroadphase.cpp +++ b/src/BulletCollision/BroadphaseCollision/btSimpleBroadphase.cpp @@ -24,8 +24,6 @@ subject to the following restrictions: #include -extern int gOverlappingPairs; - void btSimpleBroadphase::validate() { for (int i=0;i #endif @@ -77,8 +75,6 @@ btCollisionDispatcher::~btCollisionDispatcher() btPersistentManifold* btCollisionDispatcher::getNewManifold(const btCollisionObject* body0,const btCollisionObject* body1) { - gNumManifold++; - //btAssert(gNumManifold < 65535); @@ -121,7 +117,6 @@ void btCollisionDispatcher::clearManifold(btPersistentManifold* manifold) void btCollisionDispatcher::releaseManifold(btPersistentManifold* manifold) { - gNumManifold--; //printf("releaseManifold: gNumManifold %d\n",gNumManifold); clearManifold(manifold); diff --git a/src/LinearMath/btAlignedAllocator.cpp b/src/LinearMath/btAlignedAllocator.cpp index e5f6040c4..927500b2f 100644 --- a/src/LinearMath/btAlignedAllocator.cpp +++ b/src/LinearMath/btAlignedAllocator.cpp @@ -15,10 +15,6 @@ subject to the following restrictions: #include "btAlignedAllocator.h" -int gNumAlignedAllocs = 0; -int gNumAlignedFree = 0; -int gTotalBytesAlignedAllocs = 0;//detect memory leaks - static void *btAllocDefault(size_t size) { return malloc(size); @@ -163,9 +159,6 @@ void* btAlignedAllocInternal (size_t size, int alignment,int line,char* filen // printf("big alloc!%d\n", size); // } - gTotalBytesAlignedAllocs += size; - gNumAlignedAllocs++; - int sz4prt = 4*sizeof(void *); @@ -190,7 +183,6 @@ int sz4prt = 4*sizeof(void *); ret = (void *)(real);//?? } - printf("allocation %d at address %x, from %s,line %d, size %d (total allocated = %d)\n",allocId,real, filename,line,size,gTotalBytesAlignedAllocs); allocId++; int* ptr = (int*)ret; @@ -204,7 +196,6 @@ void btAlignedFreeInternal (void* ptr,int line,char* filename) void* real; if (ptr) { - gNumAlignedFree++; btDebugPtrMagic p; p.vptr = ptr; @@ -229,11 +220,6 @@ void btAlignedFreeInternal (void* ptr,int line,char* filename) } } - - gTotalBytesAlignedAllocs -= size; - - int diff = gNumAlignedAllocs-gNumAlignedFree; - printf("free %d at address %x, from %s,line %d, size %d (total remain = %d in %d non-freed allocations)\n",allocId,real, filename,line,size, gTotalBytesAlignedAllocs, diff); sFreeFunc(real); } else @@ -246,7 +232,6 @@ void btAlignedFreeInternal (void* ptr,int line,char* filename) void* btAlignedAllocInternal (size_t size, int alignment) { - gNumAlignedAllocs++; void* ptr; ptr = sAlignedAllocFunc(size, alignment); // printf("btAlignedAllocInternal %d, %x\n",size,ptr); @@ -260,7 +245,6 @@ void btAlignedFreeInternal (void* ptr) return; } - gNumAlignedFree++; // printf("btAlignedFreeInternal %x\n",ptr); sAlignedFreeFunc(ptr); }