fix btSimpleBroadphase, it shouldn't store the allocated handles, they are simply in m_pHandles.

Thanks to Ole K. for reporting the issue:
http://www.bulletphysics.com/Bullet/phpBB3/viewtopic.php?f=9&t=2560
This commit is contained in:
erwin.coumans
2008-09-04 19:31:37 +00:00
parent d2760b18aa
commit 7234a61910
2 changed files with 32 additions and 50 deletions

View File

@@ -62,10 +62,8 @@ btSimpleBroadphase::btSimpleBroadphase(int maxProxies, btOverlappingPairCache* o
{ {
m_pHandles[i].SetNextFree(i + 1); m_pHandles[i].SetNextFree(i + 1);
m_pHandles[i].m_uniqueId = i+2;//any UID will do, we just avoid too trivial values (0,1) for debugging purposes m_pHandles[i].m_uniqueId = i+2;//any UID will do, we just avoid too trivial values (0,1) for debugging purposes
m_pHandles[i].SetNextAllocated(-1);
} }
m_pHandles[maxProxies - 1].SetNextFree(0); m_pHandles[maxProxies - 1].SetNextFree(0);
m_pHandles[maxProxies - 1].SetNextAllocated(-1);
} }
@@ -179,31 +177,29 @@ void btSimpleBroadphase::calculateOverlappingPairs(btDispatcher* dispatcher)
//first check for new overlapping pairs //first check for new overlapping pairs
int i,j; int i,j;
if (m_firstAllocatedHandle >= 0) if (m_numHandles >= 0)
{ {
btSimpleBroadphaseProxy* proxy0 = &m_pHandles[m_firstAllocatedHandle];
for (i=0;i<m_numHandles;i++) for (i=0;i<m_numHandles;i++)
{ {
btSimpleBroadphaseProxy* proxy1 = &m_pHandles[m_firstAllocatedHandle]; btSimpleBroadphaseProxy* proxy0 = &m_pHandles[i];
for (j=0;j<m_numHandles;j++) for (j=i+1;j<m_numHandles;j++)
{ {
btSimpleBroadphaseProxy* proxy1 = &m_pHandles[j];
btAssert(proxy0 != proxy1);
if (proxy0 != proxy1) btSimpleBroadphaseProxy* p0 = getSimpleProxyFromProxy(proxy0);
btSimpleBroadphaseProxy* p1 = getSimpleProxyFromProxy(proxy1);
if (aabbOverlap(p0,p1))
{ {
btSimpleBroadphaseProxy* p0 = getSimpleProxyFromProxy(proxy0); if ( !m_pairCache->findPair(proxy0,proxy1))
btSimpleBroadphaseProxy* p1 = getSimpleProxyFromProxy(proxy1);
if (aabbOverlap(p0,p1))
{
if ( !m_pairCache->findPair(proxy0,proxy1))
{
m_pairCache->addOverlappingPair(proxy0,proxy1);
}
} else
{ {
m_pairCache->addOverlappingPair(proxy0,proxy1);
}
} else
{
if (!m_pairCache->hasDeferredRemoval()) if (!m_pairCache->hasDeferredRemoval())
{ {
if ( m_pairCache->findPair(proxy0,proxy1)) if ( m_pairCache->findPair(proxy0,proxy1))
@@ -211,14 +207,8 @@ void btSimpleBroadphase::calculateOverlappingPairs(btDispatcher* dispatcher)
m_pairCache->removeOverlappingPair(proxy0,proxy1,dispatcher); m_pairCache->removeOverlappingPair(proxy0,proxy1,dispatcher);
} }
} }
}
} }
proxy1 = &m_pHandles[proxy1->GetNextAllocated()];
} }
proxy0 = &m_pHandles[proxy0->GetNextAllocated()];
} }
if (m_ownsPairCache && m_pairCache->hasDeferredRemoval()) if (m_ownsPairCache && m_pairCache->hasDeferredRemoval())
@@ -273,8 +263,8 @@ void btSimpleBroadphase::calculateOverlappingPairs(btDispatcher* dispatcher)
{ {
m_pairCache->cleanOverlappingPair(pair,dispatcher); m_pairCache->cleanOverlappingPair(pair,dispatcher);
// m_overlappingPairArray.swap(i,m_overlappingPairArray.size()-1); // m_overlappingPairArray.swap(i,m_overlappingPairArray.size()-1);
// m_overlappingPairArray.pop_back(); // m_overlappingPairArray.pop_back();
pair.m_pProxy0 = 0; pair.m_pProxy0 = 0;
pair.m_pProxy1 = 0; pair.m_pProxy1 = 0;
m_invalidPair++; m_invalidPair++;
@@ -283,16 +273,16 @@ void btSimpleBroadphase::calculateOverlappingPairs(btDispatcher* dispatcher)
} }
///if you don't like to skip the invalid pairs in the array, execute following code: ///if you don't like to skip the invalid pairs in the array, execute following code:
#define CLEAN_INVALID_PAIRS 1 #define CLEAN_INVALID_PAIRS 1
#ifdef CLEAN_INVALID_PAIRS #ifdef CLEAN_INVALID_PAIRS
//perform a sort, to sort 'invalid' pairs to the end //perform a sort, to sort 'invalid' pairs to the end
overlappingPairArray.quickSort(btBroadphasePairSortPredicate()); overlappingPairArray.quickSort(btBroadphasePairSortPredicate());
overlappingPairArray.resize(overlappingPairArray.size() - m_invalidPair); overlappingPairArray.resize(overlappingPairArray.size() - m_invalidPair);
m_invalidPair = 0; m_invalidPair = 0;
#endif//CLEAN_INVALID_PAIRS #endif//CLEAN_INVALID_PAIRS
} }
} }

View File

@@ -25,7 +25,7 @@ struct btSimpleBroadphaseProxy : public btBroadphaseProxy
btVector3 m_min; btVector3 m_min;
btVector3 m_max; btVector3 m_max;
int m_nextFree; int m_nextFree;
int m_nextAllocated;
// int m_handleId; // int m_handleId;
@@ -42,8 +42,7 @@ struct btSimpleBroadphaseProxy : public btBroadphaseProxy
SIMD_FORCE_INLINE void SetNextFree(int next) {m_nextFree = next;} SIMD_FORCE_INLINE void SetNextFree(int next) {m_nextFree = next;}
SIMD_FORCE_INLINE int GetNextFree() const {return m_nextFree;} SIMD_FORCE_INLINE int GetNextFree() const {return m_nextFree;}
SIMD_FORCE_INLINE void SetNextAllocated(int next) {m_nextAllocated = next;}
SIMD_FORCE_INLINE int GetNextAllocated() const {return m_nextAllocated;}
}; };
@@ -57,22 +56,19 @@ protected:
int m_numHandles; // number of active handles int m_numHandles; // number of active handles
int m_maxHandles; // max number of handles int m_maxHandles; // max number of handles
btSimpleBroadphaseProxy* m_pHandles; // handles pool btSimpleBroadphaseProxy* m_pHandles; // handles pool
void* m_pHandlesRawPtr; void* m_pHandlesRawPtr;
int m_firstFreeHandle; // free handles list int m_firstFreeHandle; // free handles list
int m_firstAllocatedHandle; int m_firstAllocatedHandle;
int allocHandle() int allocHandle()
{ {
btAssert(m_firstFreeHandle);
int freeHandle = m_firstFreeHandle; int freeHandle = m_firstFreeHandle;
m_firstFreeHandle = m_pHandles[freeHandle].GetNextFree(); m_firstFreeHandle = m_pHandles[freeHandle].GetNextFree();
m_pHandles[freeHandle].SetNextAllocated(m_firstAllocatedHandle);
m_firstAllocatedHandle = freeHandle;
m_numHandles++; m_numHandles++;
return freeHandle; return freeHandle;
} }
@@ -84,13 +80,9 @@ protected:
proxy->SetNextFree(m_firstFreeHandle); proxy->SetNextFree(m_firstFreeHandle);
m_firstFreeHandle = handle; m_firstFreeHandle = handle;
m_firstAllocatedHandle = proxy->GetNextAllocated();
proxy->SetNextAllocated(-1);
m_numHandles--; m_numHandles--;
} }
btOverlappingPairCache* m_pairCache; btOverlappingPairCache* m_pairCache;
bool m_ownsPairCache; bool m_ownsPairCache;