DanielChappuis / reactphysics3d

Open source C++ physics engine library in 3D
http://www.reactphysics3d.com
zlib License
1.54k stars 224 forks source link

void PhysicsWorld::createIslands() dirty contactPairIndex crash #366

Closed darktemplar216 closed 8 months ago

darktemplar216 commented 10 months ago

in void PhysicsWorld::createIslands()

const uint32 nbBodyContactPairs = static_cast(mRigidBodyComponents.mContactPairs[bodyToVisitIndex].size()); for (uint32 p=0; p < nbBodyContactPairs; p++) {

            const uint32 contactPairIndex = mRigidBodyComponents.mContactPairs[bodyToVisitIndex][p];
            ContactPair& pair = (*mCollisionDetection.mCurrentContactPairs)[contactPairIndex];

When using Trigger and RigidBody together, sometimes mRigidBodyComponents.mContactPairs contain dirty indices from the old frames and indexing mCollisionDetection.mCurrentContactPairs crashes the program by hitting the Assertion inside Array.

Seems that only cleaning the Enabled RigidBodyComponents leaves the dirty data behind

const uint32 nbRigidBodyEnabledComponents = mRigidBodyComponents.getNbEnabledComponents(); for (uint32 b=0; b < nbRigidBodyEnabledComponents; b++) { mRigidBodyComponents.mContactPairs[b].clear(); }

I change this loop to all rigidbodyComponents

for (uint32 b = 0; b < nbRigidBodyComponents; b++) { mRigidBodyComponents.mContactPairs[b].clear(); }

seems everything's fine and prevented the crash.

Does it makes any sense to you? Daniel.

DanielChappuis commented 10 months ago

Thanks a lot for reporting this. I will take a look at this as soon as I have some time.

darktemplar216 commented 10 months ago

Thanks, dude, nobody knows this lib better than you. Thumbs up

DanielChappuis commented 9 months ago

This issue is already fixed by some refactoring I did in the 'develop' branch. This will be part of the next release of the library. Again, thanks a lot for reporting the issue and for the fix also.

DanielChappuis commented 8 months ago

This is now fixed in version v0.10.0 of the library. Thanks a lot for reporting the issue.