I have a program which integrates PhysX for offline rigidbody simulations.
I’m getting a crash when instantiating a lot of rigidbodies in close proximity (100k+ RBs, generating millions of contacts). The crash does not occur when instantiating less rigidbodies (I’m not sure the exact number of RBs that triggers the crash…but everything runs fine when instantiating only 1000 RBs, for example)
The crash happens in PxsNphaseImplementationContext::registerContactManager because PxsContactManager* cm is not initialized (it has a value of 0xcdcdcdcdcdcdcdcc).
The only place in code where PxsContactManagers seem to be initialized is in Sc::Scene::preallocateContactManagers. The code flow seems to be as follows:
mPreallocatedContactManagers.forceSize_Unsafe is called to resize the cm array
mOverlapFilterTasks are iterated, initializing cms as required (through calls to mLLContext->getContactManagerPool().preallocate(…))
My assumption is that at the end of the call to preallocateContactManagers, each pointer in the mPreallocatedContactManagers array will point to valid memory. However, with large numbers of rigidbodies, some pointers remain unassigned, despite being referenced later in code (which causes the crash).
I’ve been trying to figure out where exactly things are going wrong, but there are a ton of different branches and dependencies within all these functions that are difficult to trace, especially when the number of contacts generated with my 100k rigidbodies is huge (multi-millions). Do any PhysX devs have an idea where to start looking first to figure out why some pointers are being skipped during the initialization process? I still don’t quite follow the logic of what’s going on in CmPool::preallocate, but it seems like that would be the best place to start looking? Or are my assumptions about how/where cms are initialized completely wrong?
For reference, when the crash occurs, the value of ‘totalCreatedPairs’ (which mPreallocatedContactManagers is being resized to) is 48467668. So a huge number, but not so huge that I’d expect it to cause the crashes I’m experiencing.
It’s also worth noting that when I compile the simulation in Debug mode, no PX assertions are triggered. So I’m not simply missing a checksomewhere.