Fix onBodyContact being called on removed nodes


Since collision callbacks happen in the physx simulation thread we need
to store these callbacks. Otherwise, if an object is deleted in the same
frame a 'onBodyContact' signal is enqueued and a crash will happen.
Therefore we save these contact callbacks and run them at the end of the
physics frame when we know if the objects are deleted or not.

We move the mutex in QPhysicsWorld::deregisterNode to cover also the
decoupling of the physics node since this node can be read
asynchronously in the 'onContact' physx callback.

In the 'onContact' callback we check if the node is removed _before_
dereferencing it and checking 'm_backendObject'.

Fixes: QTBUG-121033
Pick-to: 6.7 6.6 6.5
Change-Id: I2412502baa6ede1897a4d1377e8c52a8339471d2
Reviewed-by: Andy Nichols <andy.nichols@qt.io>
commit87d7c334002997ea54a10670009b0a8a49b0a436
parentec3f8b2e98c38a22ceda6f50ebd54b6bb7f428fc
authorJonas Karlsson <jonas.karlsson@qt.io>
committerJonas Karlsson <jonas.karlsson@qt.io>
commit timeWed, 24 Jan 2024 16:32:27 +0100