We sometimes crash in Gu::SinglePersistentContactManifold::reduceBatchContactsConvex, line 1735:
chosen[index] = true;
Doesn't happen in-house so all I have is a crash dump, but AFAICT index is invalid (GU_MANIFOLD_INVALID_INDEX), so clearly out of bounds.
My best theory is that when we do reduceManifoldContactsInDifferentPatches it drops 'duplicate' contacts by decreasing mEndIndex but it does not modify "root" patch's mTotalSize.
That means if we start with total size over GU_SINGLE_MANIFOLD_CACHE_SIZE we might hit the contact reduction path in addBatchManifoldContactsConvex. From that, it's possible to hit reduceBatchContactsConvex with fewer than 6 'live' contacts.
In our case it seems to be 2, so 2 'live' contacts, total size = 7, the third pick starts at index=invalid, but it can't update it, since both 'slots' are chosen so it fails the if(!chosen[i]) test.
The fix seems to be 1 line in reduceManifoldContactsInDifferentPatches:
manifoldContacts[l] = manifoldContacts[nextPatch->mEndIndex-1];
nextPatch->mEndIndex--;
-
contactPatch[i]->mTotalSize--;
... but to be 100% honest I'm not quite sure if I fully understand what's going on so could use a second opinion
We sometimes crash in Gu::SinglePersistentContactManifold::reduceBatchContactsConvex, line 1735:
chosen[index] = true;
Doesn't happen in-house so all I have is a crash dump, but AFAICT index is invalid (GU_MANIFOLD_INVALID_INDEX), so clearly out of bounds.
My best theory is that when we do reduceManifoldContactsInDifferentPatches it drops 'duplicate' contacts by decreasing mEndIndex but it does not modify "root" patch's mTotalSize.
That means if we start with total size over GU_SINGLE_MANIFOLD_CACHE_SIZE we might hit the contact reduction path in addBatchManifoldContactsConvex. From that, it's possible to hit reduceBatchContactsConvex with fewer than 6 'live' contacts.
In our case it seems to be 2, so 2 'live' contacts, total size = 7, the third pick starts at index=invalid, but it can't update it, since both 'slots' are chosen so it fails the if(!chosen[i]) test.
The fix seems to be 1 line in reduceManifoldContactsInDifferentPatches:
manifoldContacts[l] = manifoldContacts[nextPatch->mEndIndex-1];
nextPatch->mEndIndex--;
... but to be 100% honest I'm not quite sure if I fully understand what's going on so could use a second opinion