Skip to content

Commit

Permalink
Fix rare crash where custom broadphase fails to reject null collision…
Browse files Browse the repository at this point in the history
… objects
  • Loading branch information
ZealanL committed May 12, 2024
1 parent 67e20ee commit d6c577a
Showing 1 changed file with 15 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -312,9 +312,11 @@ void btRSBroadphase::rayTest(const btVector3& rayFrom, const btVector3& rayTo, b

Cell& cell = cells[GetCellIdx(rayFrom)];
for (auto& otherProxy : cell.staticHandles)
rayCallback.process(otherProxy);
if (otherProxy->m_clientObject)
rayCallback.process(otherProxy);
for (auto& otherProxy : cell.dynHandles)
rayCallback.process(otherProxy);
if (otherProxy->m_clientObject)
rayCallback.process(otherProxy);
} else {
static std::once_flag onceFlag;
std::call_once(onceFlag,
Expand Down Expand Up @@ -342,19 +344,17 @@ void btRSBroadphase::aabbTest(const btVector3& aabbMin, const btVector3& aabbMax

for (int i = 0; i <= m_LastHandleIndex; i++) {
btRSBroadphaseProxy* proxy = &m_pHandles[i];
if (!proxy->m_clientObject) {
if (!proxy->m_clientObject)
continue;
}

if (TestAabbAgainstAabb2(aabbMin, aabbMax, proxy->m_aabbMin, proxy->m_aabbMax)) {
callback.process(proxy);
}
}
}

bool btRSBroadphase::aabbOverlap(btRSBroadphaseProxy* proxy0, btRSBroadphaseProxy* proxy1) {
return proxy0->m_aabbMin[0] <= proxy1->m_aabbMax[0] && proxy1->m_aabbMin[0] <= proxy0->m_aabbMax[0] &&
proxy0->m_aabbMin[1] <= proxy1->m_aabbMax[1] && proxy1->m_aabbMin[1] <= proxy0->m_aabbMax[1] &&
proxy0->m_aabbMin[2] <= proxy1->m_aabbMax[2] && proxy1->m_aabbMin[2] <= proxy0->m_aabbMax[2];
return TestAabbAgainstAabb2(proxy0->m_aabbMin, proxy0->m_aabbMax, proxy1->m_aabbMin, proxy1->m_aabbMax);
}

//then remove non-overlapping ones
Expand All @@ -367,6 +367,7 @@ class CheckOverlapCallback : public btOverlapCallback
};

void btRSBroadphase::calculateOverlappingPairs(btCollisionDispatcher* dispatcher) {

bool shouldRemove = !m_pairCache->hasDeferredRemoval();
if (m_numHandles >= 0) {
int new_largest_index = -1;
Expand All @@ -385,6 +386,9 @@ void btRSBroadphase::calculateOverlappingPairs(btCollisionDispatcher* dispatcher
Cell& cell = cells[proxy->cellIdx];

for (auto& otherProxy : cell.staticHandles) {
if (!otherProxy->m_clientObject)
continue;

totalStaticPairs++;

if (aabbOverlap(proxy, otherProxy)) {
Expand All @@ -407,6 +411,9 @@ void btRSBroadphase::calculateOverlappingPairs(btCollisionDispatcher* dispatcher
if (otherProxy == proxy)
continue;

if (!otherProxy->m_clientObject)
continue;

totalDynPairs++;

if (aabbOverlap(proxy, otherProxy)) {
Expand Down Expand Up @@ -440,5 +447,5 @@ bool btRSBroadphase::testAabbOverlap(btBroadphaseProxy* proxy0, btBroadphaseProx
}

void btRSBroadphase::resetPool(btCollisionDispatcher* dispatcher) {
//not yet
// TODO: ?
}

0 comments on commit d6c577a

Please sign in to comment.