Problems with collision detection determinism

A place to discuss everything related to Newton Dynamics.

Moderators: Sascha Willems, walaber

Problems with collision detection determinism

Postby BS-er » Tue May 12, 2009 12:13 am

I'm using Newton only for pairwise collision detection. I'm having a problem (in Newton 1.53 as well as the 2.0 public beta x32) where pairwise tests between convex hulls can generate slightly different results for the same inputs, under certain circumstances.

Once any convex hulls are created, their collision test behavior is completely consistent from then on. It would seem that the point of creation (or maybe order of creation) may be where an anomaly may or may not be introduced. Somehow a convex hull may turn out slightly different given the same vertex array and arguments.

There are 2 cases being compared, A and B. They are not run in the same application session. The application is shut down and started again in between. There are differences in these two sessions, i.e. levels run in different orders.

I have extensively checked between 2 different cases to make sure of the following:

For the call to NewtonCreateConvexHull, the vertex count (=6147), vertex array, stride, tolerance and offset matrix are exactly the same. I performed diffs using output of a debugger memory window to confirm the vertex arrays and matrix were the same.

The vertex count is correct. I'm not causing Newton to overrun the array. The offset matrix is 4x4 floating point, and is an identity matrix.

for the call to NewtonCollisionCollide, maxSize=1, and the matrices are the same between case A and B (and are 4x4 floating point). The same convex hull instance is used for both colliders.

The newton world is set up the same in both cases, at launch:
Code: Select all
m_world = NewtonCreate( NewtonAlloc, NewtonFree );
NewtonSetThreadsCount (m_world, 1);

I set up custom malloc and free callbacks, with malloc callback setting all the allocated memory to 0. I also put a call to NewtonInvalidateCache before each call to NewtonCreateConvexHull, just trying different things.

The contact, normal and depth results from the call to NewtonCollisionCollide are very slightly different in the 2 cases. It's only certain matrices that show a difference.

It will be a fatal issue for me if the computation may be affected by things such as the order that the player loads missions etc. All my data so far suggests that it's possible to create convex hulls using the exact same data, but collision tests can be slightly different, even though all data you input to these functions is exactly the same. the perturbation might be related to order of creation, or I speculate that is could depend on uninitialized variables somewhere. I'm not sure what the external influence might be. All I know is that the data I am feeding these functions is the same.

I'd appreciate any insight or suggestions. My next step would be to try and prove my case with an easy-to-compile test app, but first I want to see if there are known issues or resolutions.
BS-er
 
Posts: 3
Joined: Thu Jun 21, 2007 10:37 pm
Location: Niskayuna, NY

Re: Problems with collision detection determinism

Postby JernejL » Tue May 12, 2009 5:24 am

Which computation platform architecture are you using in newton? if you use sse and other extensions they do not guarantee precision, you need to set it to use plain x86 mode to have guaranteed determinism, this probably affects simulation as well as in your case collision detection.
Help improving the Newton Game Dynamics WIKI
User avatar
JernejL
 
Posts: 1587
Joined: Mon Dec 06, 2004 2:00 pm
Location: Slovenia

Re: Problems with collision detection determinism

Postby Julio Jerez » Tue May 12, 2009 10:14 am

you are saying the you are calling the function NewtonCollisionCollide, with thr exat same imput data and you are geting different results?
do you have a test?
Julio Jerez
Moderator
Moderator
 
Posts: 12426
Joined: Sun Sep 14, 2003 2:18 pm
Location: Los Angeles

Re: Problems with collision detection determinism

Postby BS-er » Tue May 12, 2009 10:44 am

I did not explicitly call a function to set up the platform. Thanks for that tip.

I've verified that all inputs to NewtonCreateConvexHull and NewtonCollisionCollide are the same in case A and B, but the output is slightly different. As I said, the output matches when using some matrices in a collision pair, and doesn't match for others.

I'll try setting it up for plain x86 and see if that helps. If not, I will whip up a small test app and see if it has the same results.
BS-er
 
Posts: 3
Joined: Thu Jun 21, 2007 10:37 pm
Location: Niskayuna, NY

Re: Problems with collision detection determinism

Postby BS-er » Wed May 13, 2009 6:10 pm

I'm still digging into this problem. There is still a problem even when using the common denominator platform model.

I'm using the Ogre engine. This post reveals a potential problem, where DirectX can change the FPU behavior. Ogre has a setting to fix it, but that has not alleviated the problem. This at least shows that there are ways that other code can easily influence calculations done by Newton or other software.

I suspect that the problem is some sort of influence on the FPU, even if the Ogre side isn't to blame. The computations are only off by a very slight, almost negligible amount, which makes me thing that its something other than an outright glitch or design flaw in the affected calculations. It would be nice to be able to zero in on the culprit if that is the case. I'm using Lua as well, which does a lot of double-precision calculations. A thorough check of the project settings may be in order as well.

I hope to find the culprit soon!
BS-er
 
Posts: 3
Joined: Thu Jun 21, 2007 10:37 pm
Location: Niskayuna, NY

Re: Problems with collision detection determinism

Postby JernejL » Wed May 13, 2009 7:11 pm

You could try ressetting the FPU setup using FLDCW asm command.. like Set8087CW($133F) or whatever is the equivalent in your programming language every time before you use newton physics commands and see if that's the cause. but remember if you feed it any numerical input from your game you need to ensure that data isn't compromised by any specific fpu setup during your game processing aswell.
Help improving the Newton Game Dynamics WIKI
User avatar
JernejL
 
Posts: 1587
Joined: Mon Dec 06, 2004 2:00 pm
Location: Slovenia

Re: Problems with collision detection determinism

Postby agi_shi » Thu Jun 11, 2009 5:11 pm

Just for info: I use Ogre, double-precision mode (otherwise we had extremely weird Lua issues), and Newton - to achieve 100% determinism on every simulation run, I completely reset the scene to the original values (position/rotation/velocity/etc.), clear the world cache, and make sure Newton is using 1 thread (we did not find any deterministic problems between the various solvers/architectures, they were all deterministic). In cases where we do not need a 100% deterministic resimulation, we obviously enable more than 1 thread ;)
agi_shi
 
Posts: 263
Joined: Fri Aug 17, 2007 6:54 pm


Return to General Discussion

Who is online

Users browsing this forum: No registered users and 3 guests

cron