Problem with dgSpatialMatrix::Inverse() [SOLVED]

Report any bugs here and we'll post fixes

Moderators: Sascha Willems, Thomas

Problem with dgSpatialMatrix::Inverse() [SOLVED]

Postby misho » Thu May 09, 2019 3:40 am

I am getting an assert fail on

Code: Select all
dgAssert(pivot > dgFloat32(1.0e-6f));


in dgSpatialMatrix::Inverse(), line 700. I'm unsure if it is something I added to my code (It's been a while since I tested this particular functionality), but this happens only in debug config. There are 10 instances of the same assertion, and if I ignore them all, the execution continues without effect. I'm using DOUBLE PRECISION, so the build config is debug_double.

I tried changing the value inside the brackets to:

Code: Select all
dgAssert(pivot > dgFloat32(1.0e-12f));


and with this change, everything works fine - the asserts are gone, and execution continues as expected. release_double config works without any problems. I am not sure if something changed in Newton libraries around that area, or if it is the result of changes in my code somewhere in the past few weeks, but I would really appreciate it if someone can point me in the right direction in tracking this issue down.

Thanks!
Last edited by misho on Sun May 12, 2019 7:19 pm, edited 1 time in total.
Misho Katulic
CTO, FSX SpacePort
TerraBuilder
www.terrabuilder.com
misho
 
Posts: 673
Joined: Tue May 04, 2010 10:13 am

Re: Problem with dgSpatialMatrix::Inverse()

Postby Julio Jerez » Thu May 09, 2019 7:52 am

could you show me the trace stack whe is happens, that's a bad matrix trying to be inverted.
Julio Jerez
Moderator
Moderator
 
Posts: 12249
Joined: Sun Sep 14, 2003 2:18 pm
Location: Los Angeles

Re: Problem with dgSpatialMatrix::Inverse()

Postby misho » Thu May 09, 2019 12:10 pm

Sure - here it is:

Code: Select all
>   FSXSpacePort.dll!dgSpatialMatrix::Inverse(int rows) Line 700   C++
    FSXSpacePort.dll!dgSkeletonContainer::dgNode::CalculateJointDiagonal(const dgSpatialMatrix * const bodyMassArray, dgSpatialMatrix * const jointMassArray) Line 266   C++
    FSXSpacePort.dll!dgSkeletonContainer::dgNode::Factorize(const dgJointInfo * const jointInfoArray, const dgLeftHandSide * const leftHandSide, const dgRightHandSide * const rightHandSide, dgSpatialMatrix * const bodyMassArray, dgSpatialMatrix * const jointMassArray) Line 211   C++
    FSXSpacePort.dll!dgSkeletonContainer::InitMassMatrix(const dgJointInfo * const jointInfoArray, const dgLeftHandSide * const leftHandSide, dgRightHandSide * const rightHandSide) Line 1415   C++
    FSXSpacePort.dll!dgWorldDynamicUpdate::CalculateClusterReactionForces(const dgBodyCluster * const cluster, int threadID, double timestep) Line 701   C++
    FSXSpacePort.dll!dgWorldDynamicUpdate::ResolveClusterForces(dgBodyCluster * const cluster, int threadID, double timestep) Line 46   C++
    FSXSpacePort.dll!dgWorldDynamicUpdate::CalculateClusterReactionForcesKernel(void * const context, void * const worldContext, int threadID) Line 580   C++
    FSXSpacePort.dll!dgThreadHive::QueueJob(void(*)(void * const, void * const, int) callback, void * const context0, void * const context1, const char * const functionName) Line 322   C++
    FSXSpacePort.dll!dgWorldDynamicUpdate::UpdateDynamics(double timestep) Line 138   C++
    FSXSpacePort.dll!dgWorld::StepDynamics(double timestep) Line 919   C++
    FSXSpacePort.dll!dgWorld::RunStep() Line 988   C++
    FSXSpacePort.dll!dgWorld::TickCallback(int threadID) Line 1020   C++
    FSXSpacePort.dll!dgMutexThread::Execute(int threadID) Line 59   C++
    FSXSpacePort.dll!dgThread::dgThreadSystemCallback(void * threadData) Line 170   C++


As this is inside inner workings of Newton, I have no entry point on my side and I'm not sure what part of my code causes it...
Misho Katulic
CTO, FSX SpacePort
TerraBuilder
www.terrabuilder.com
misho
 
Posts: 673
Joined: Tue May 04, 2010 10:13 am

Re: Problem with dgSpatialMatrix::Inverse()

Postby Julio Jerez » Thu May 09, 2019 2:36 pm

that does no help much, this has to do wi an optimization that I made to the calculation of the inverse.
instead of using full pivot it uses reduction to echelon form.

this can generate bad matrix if the matrix has a high condition number, by the check for condition number is expensive. so instead I just do a simple check that is the main diagonal is too small I assume the matrix is valid. in more than 99.999 % of the cases the matrix is valid so the expensive check is a waste, but is possible that is case like you, and some other who use realistic values to cam up with matrix that is not necessarily bad by that have very small diagonal values.

so the better check is to check that the value is no a real zero, then if it pass that test, and is no reasonable, then do the expensive check for high condition number.
condition number test are extreme expensive. by a bad condition number is a guarantee explosion.
https://en.wikipedia.org/wiki/Condition_number

try sync and check if this passes. with the 1.0e-6 check, is important that the matrix is not a bad matrix.
Julio Jerez
Moderator
Moderator
 
Posts: 12249
Joined: Sun Sep 14, 2003 2:18 pm
Location: Los Angeles

Re: Problem with dgSpatialMatrix::Inverse()

Postby misho » Thu May 09, 2019 3:14 pm

Great, thanks for the quick turnaround! Although - I couldn't get it built (debug_double):

Code: Select all
10>  dCustomPlayerControllerManager.cpp
10>..\..\dCustomJoints\dCustomPlayerControllerManager.cpp(270): error C2672: 'dGaussSeidelLcpSor': no matching overloaded function found
10>..\..\dCustomJoints\dCustomPlayerControllerManager.cpp(270): error C2782: 'void dGaussSeidelLcpSor(const int,const int,const T *const ,T *const ,const T *const ,const int *const ,const T *const ,const T *const ,T,int,T)': template parameter 'T' is ambiguous
10>  E:\newton-dynamics-master\sdk\dMath\dMathDefines.h(774): note: see declaration of 'dGaussSeidelLcpSor'
10>  ..\..\dCustomJoints\dCustomPlayerControllerManager.cpp(270): note: could be 'float'
10>  ..\..\dCustomJoints\dCustomPlayerControllerManager.cpp(270): note: or       'double'
10>..\..\dCustomJoints\dCustomPlayerControllerManager.cpp(270): error C2784: 'void dGaussSeidelLcpSor(const int,const int,const T *const ,T *const ,const T *const ,const int *const ,const T *const ,const T *const ,T,int,T)': could not deduce template argument for 'T' from 'float'
10>  E:\newton-dynamics-master\sdk\dMath\dMathDefines.h(774): note: see declaration of 'dGaussSeidelLcpSor'
Misho Katulic
CTO, FSX SpacePort
TerraBuilder
www.terrabuilder.com
misho
 
Posts: 673
Joined: Tue May 04, 2010 10:13 am

Re: Problem with dgSpatialMatrix::Inverse()

Postby Julio Jerez » Thu May 09, 2019 4:36 pm

try again.
Julio Jerez
Moderator
Moderator
 
Posts: 12249
Joined: Sun Sep 14, 2003 2:18 pm
Location: Los Angeles

Re: Problem with dgSpatialMatrix::Inverse()

Postby misho » Thu May 09, 2019 5:06 pm

Ok - I got the lib built.

However - that fix didn't work. I am getting the assert at the different line (but I presume it is the modified version of original statement):

Code: Select all
         dgAssert((pivot > dgFloat32(1.0e-6f)) || (dgConditionNumber(rows, 6, (dgFloat64*)&m_rows[0]) < dgFloat32(1.0e5f)));


Also, with this new build, dCustom6DOF.h cannot be found. This affects all the buoyancy code I worked on (but not using at the moment), which I disabled just to see if this fix worked.
Misho Katulic
CTO, FSX SpacePort
TerraBuilder
www.terrabuilder.com
misho
 
Posts: 673
Joined: Tue May 04, 2010 10:13 am

Re: Problem with dgSpatialMatrix::Inverse()

Postby Julio Jerez » Thu May 09, 2019 5:51 pm

ok first thing is the dCustom6DOF.h was renamed dCustomSixdof.h

second unless there is a bug in the debug code, this seem a serious bug,
I added code to trace the matrix

Code: Select all
         if (!((pivot > dgFloat32(1.0e-6f)) || (dgConditionNumber(rows, 6, (dgFloat64*)&m_rows[0]) < dgFloat32(1.0e5f))))
         {
            for (dgInt32 m = 0; m < rows; m++) {
               for (dgInt32 n = 0; n < rows; n++) {
                  dgTrace(("%f ", m_rows[m][n]));
               }
               dgTrace(("%f\n"));
            }
            dgAssert(0);
         }

try sync and rename the joint, the run until it print the matrix, to see if it really a bad matrix of a bug in the debug check. setting the tol to 1e-12 if a big mistake.
Julio Jerez
Moderator
Moderator
 
Posts: 12249
Joined: Sun Sep 14, 2003 2:18 pm
Location: Los Angeles

Re: Problem with dgSpatialMatrix::Inverse()

Postby misho » Thu May 09, 2019 6:49 pm

Ok - header renamed - All my buoyancy code is now broken, I can see you did some work in the demoSandBox code... namely, dTriggerEventType is gone... but that's ok, I can re-visit that code later when I decide to use it...

and, here's the matrix:

Code: Select all
The thread 0x2410 has exited with code 0 (0x0).
0.000000 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000
0.000000 1.000000 0.000000 0.000000 0.000000 0.000000 0.000000
0.000000 0.000000 1.000000 0.000000 0.000000 0.000000 0.000000
0.000000 0.000000 0.000000 0.666667 -0.000000 0.000000 0.000000
0.000000 0.000000 0.000000 -0.000000 0.666667 0.000000 0.000000
0.000000 0.000000 0.000000 0.000000 0.000000 0.666667 0.000000
Debug Assertion Failed!


Thanks!
Misho Katulic
CTO, FSX SpacePort
TerraBuilder
www.terrabuilder.com
misho
 
Posts: 673
Joined: Tue May 04, 2010 10:13 am

Re: Problem with dgSpatialMatrix::Inverse()

Postby misho » Thu May 09, 2019 7:19 pm

I just wanted to add that this fix makes my release version crash as well... :roll:

Misho
Misho Katulic
CTO, FSX SpacePort
TerraBuilder
www.terrabuilder.com
misho
 
Posts: 673
Joined: Tue May 04, 2010 10:13 am

Re: Problem with dgSpatialMatrix::Inverse()

Postby Julio Jerez » Thu May 09, 2019 7:20 pm

yes it would, because I made a mistake. I added the code below at the beginning of the function
for (dgInt32 i = 0; i < rows; i++) {
*((dgFloat64*)&m_rows[i * 6]) = 1.e-7f;
}

that was my mistake, is fixed now please try again.
Julio Jerez
Moderator
Moderator
 
Posts: 12249
Joined: Sun Sep 14, 2003 2:18 pm
Location: Los Angeles

Re: Problem with dgSpatialMatrix::Inverse()

Postby misho » Thu May 09, 2019 7:42 pm

OK, that worked!!! Thanks!!

Misho
Misho Katulic
CTO, FSX SpacePort
TerraBuilder
www.terrabuilder.com
misho
 
Posts: 673
Joined: Tue May 04, 2010 10:13 am

Re: Problem with dgSpatialMatrix::Inverse()

Postby Julio Jerez » Thu May 09, 2019 8:09 pm

ha cool, it did not print any error?
I put the high condition number test.
so basically you matrix is nor has a high condition number, is just that is a matrix of small numbers.
an the quick check for small value on the menu diagonal is nor enough.
if the assert happens the check is there commented out.
Julio Jerez
Moderator
Moderator
 
Posts: 12249
Joined: Sun Sep 14, 2003 2:18 pm
Location: Los Angeles

Re: Problem with dgSpatialMatrix::Inverse()

Postby misho » Thu May 09, 2019 10:29 pm

No - no error printed! That part seems to now work ok!

However - there is another assert, different point in the execution, and different location:

in void dCustomBallAndSocket::ApplyTwistAngleRow(const dVector& pin, dFloat twistAngle, dFloat timestep), line 312:

Code: Select all
dAssert(dAbs(twistAngle * dRadToDegree) < 10.0f);


Looks like a similar problem. In this case, twistAngle reads:

Code: Select all
twistAngle = -0.22680466430319834
Misho Katulic
CTO, FSX SpacePort
TerraBuilder
www.terrabuilder.com
misho
 
Posts: 673
Joined: Tue May 04, 2010 10:13 am


Return to Bugs and Fixes

Who is online

Users browsing this forum: No registered users and 7 guests