I'm looking into a determinism/replay issue. Specifically I setup and run a simulation, then I "rewind" to the initial state, invalidate cache, and run again. I have a rare case I'm looking into where the 2nd run doesn't give the same results as the first run.
The first difference I see when running is that one of the contacts I'm getting has the 2 contacting bodies in a different order, and the contact normal very slightly different (in addition to being the opposite direction since the bodies are swapped). So...
Question 1) If 2 bodies are in a different order when calculating contacts, is it possible that the contacts can be different (aside from the normal being in the opposite direction).
It appears that the bodies are in a different order because the broadphase tree is different. I can see that the dgBroadPhase::CalculateEntropy() and dgBroadPhase::ImproveNodeFitness() calls are giving different results.
Question 2) If I add some bodies, and then remove them, should the broadphase be the same as when I started? And does it matter if it isn't?
Question 3) If the broadphase organization needs to be the same and deterministic, is there a way to fully recalculate it at the same time I'm calling InvalidateCache?
NOTE - I'm running on an older version of Newton from September 2016 in case there have been changes to broadphase I should be aware of.