[ODE] Possible TriList Bug, TriCount too high in dCollideSTL (Bug found and fixed)

Russ arrellr at yahoo.com
Fri Feb 21 08:54:01 2003


I solved my problem, there is a small bug in Trilist
that
may only affect certain platforms, it has to do with
a comparison to dInfinity.

In dCollideSTL there is the following for loop that
looks for the smalled DifSq value and saves the
corresponding 
j value and saves it in MinDifIndex.



			dReal MinDifSq = dInfinity;
			int MinDifIndex = -1;
			for (int j = 0; j < 3; j++){
				/*dVector3 Diff;
				Diff[0] = dv[j][0] - Position[0];
				Diff[1] = dv[j][1] - Position[1];
				Diff[2] = dv[j][2] - Position[2];
				Diff[3] = REAL(0.0);

				dReal DifSq = dDOT(Diff, Diff);
				if (DifSq < MinDifSq){
					MinDifSq = DifSq;
					MinDifIndex = 0;
				}*/

				dVector3 vu;
				vu[0] = dv[1][0] - dv[0][0];
				vu[1] = dv[1][1] - dv[0][1];
				vu[2] = dv[1][2] - dv[0][2];
				vu[3] = REAL(0.0);

				dVector3 vv;
				vv[0] = dv[2][0] - dv[0][0];
				vv[1] = dv[2][1] - dv[0][1];
				vv[2] = dv[2][2] - dv[0][2];
				vv[3] = REAL(0.0);

				dReal DifSq = dFabs(dDOT(vu, vu) - dDOT(vv, vv));
				if (DifSq < MinDifSq){
					MinDifSq = DifSq;
					MinDifIndex = j;
				}
			}


For certain collisions the if at the bottom which
should be comparing the current DifSq to MinDifSq
is always false.  The result is that at the end of
the loop MinDifSq == dInifinity and MinDifIndex == -1

later when MinDifIndex is used to access an array 
element it returns NaN because you can't access a
negative array element.  I fixed this by adding

				if (MinDifIndex == -1)
				{
					MinDifSq = DifSq;
					MinDifIndex = j;
				}

to the end of the for loop.

The problem has something to do with how dInifinity
is handled, so it may be system dependent, and I may
be the only one seeing the problem.  It was pretty 
tricky to track down, (the original error was
"vector has zero size" generated by dNormalize4),
so making this fix will probably save someone else
lots of frustration in the future.

I also looked at the box-TL collider but didn't see a
similar if statement, so I think the problem was
limited 
to the sphere collider.


Russ

__________________________________________________
Do you Yahoo!?
Yahoo! Tax Center - forms, calculators, tips, more
http://taxes.yahoo.com/