czaloj / bullet

Automatically exported from code.google.com/p/bullet
0 stars 0 forks source link

Add btAxisSweep3Internal::resetPool (needed for deterministic simulations) #126

Closed GoogleCodeExporter closed 9 years ago

GoogleCodeExporter commented 9 years ago
For deterministic simulations the handle pool of btAxisSweep3 has to return the 
same handles in 
the same order for different runs (otherwise the m_uniqueId of a handle of the 
same collision 
object may differ from run to run, which results in different behaviour as this 
id is used as a hash 
key in the overlapping pair cache).

The current implementation does not have this desired behaviour: Even if none 
of the handles of 
the pool is used, the pool is not in its initial state after a simulation run 
because the linked list of 
free handles has a different order.

One solution would be to create a new btAxisSweep3 for each run, but this 
involves a lot of 
memory traffic. Therefore I suggest to add a method resetPool as in the 
attached patch which 
has to be invoked when the pool is completely unused and which restores the 
initial order of the 
linked list.

Original issue reported on code.google.com by ol...@arcor.de on 30 Oct 2008 at 10:02

Attachments:

GoogleCodeExporter commented 9 years ago
The only way we could guarantee reproducable (deterministic) results is by 
removing 
all objects from the dynamics world and re-inserting them in exactly the same 
order. 
And don't forget to reset the randseed generator, by calling

btSequentialImpulseConstraintSolver::reset

It will be very difficult to get reproducable results otherwise: all the other 
cached 
structures, such as overlapping pairs and btPersistentManifolds needs to be 
cleared 
and re-ordered too. For example: if you want to keep the overlapping pairs, you 
need 
to use the btSortedPairCache, to maintain a consistent ordering.

But we can accept the contribution, if it helps you.

Original comment by erwin.coumans on 30 Oct 2008 at 5:43

GoogleCodeExporter commented 9 years ago
Yes, I already remove all objects from the dynamics world, re-insert them 
afterwards, and reset the random 
seed. But the simulation is still not deterministic due to the linked list of 
free handles in btAxisSweep3. After a 
simulation and removal of all objects, the linked list is NOT in its initial 
state (where each handle points to its 
subsequent handle in memory), but is some permutation of this order. Therefore, 
for a deterministic simulation 
with btAxisSweep3, one has to do the steps which you mentioned, but one 
additionally has to either create a new 
btAxisSweep3 or to reset its pool. The latter is done by my patch. It seems to 
work, i.e., my simulations are 
deterministic now.

Original comment by ol...@arcor.de on 31 Oct 2008 at 6:29

GoogleCodeExporter commented 9 years ago
Good point, the linked-list needs to be reset indeed.

It has been fixed in the latest trunk:
http://code.google.com/p/bullet/source/detail?r=1448

Thanks again for the great contribution!
Erwin

Original comment by erwin.coumans on 4 Nov 2008 at 9:37