NaN value on NewtonBody Position

A place to discuss everything related to Newton Dynamics.

Moderators: Sascha Willems, walaber

NaN value on NewtonBody Position

Postby KATO2 » Tue Nov 15, 2011 6:57 pm

Hello guys.

i am running a physics simulation in linux with OgreNewt, Newton 2.33 and Ogre3D. The physics simulation is running on server.

i have already 30 objects in scene, particulary an object is in position (-10, 0.01, 98) and another in position (2.55826,1.30654,-3.69629). when i update newton world first time the object in position (2.55826,1.30654,-3.69629) changes his position to (-nan, -nan, -nan). On second update object in position (-10, 0.01, 98) changes to (-nan, -nan, -nan).

This error started after y compile Newton without -ffast-math, i removed this option because simulation frezee on newtonworld update. I don't know how to reproduces this error. but i can say that the primitive body for both objects is ConvexHull, Ground is a Box, and i have another objects whichs are a TreeCollision primitive.

i tried compiling other Newton revisions and results are same. finally, i changed thread count to 2 and this works fine, however i will follow testing, since I'm not sure the problem is solved.

anyone known how to resolve this problem?
KATO2
 
Posts: 23
Joined: Thu Nov 10, 2011 11:16 pm

Re: NaN value on NewtonBody Position

Postby Julio Jerez » Wed Nov 16, 2011 12:42 am

That is usuallay because some parameter is very oncorrect on one of the body ot the collison shapes.
you will have to buil dthe code in debug, so that you find the place where teh Nan is happeinig,
Julio Jerez
Moderator
Moderator
 
Posts: 12426
Joined: Sun Sep 14, 2003 2:18 pm
Location: Los Angeles

Re: NaN value on NewtonBody Position

Postby KATO2 » Wed Nov 16, 2011 9:52 pm

Well, i can compile Newton in debug mode, but i can trace into NewtonWorldUpdate?
KATO2
 
Posts: 23
Joined: Thu Nov 10, 2011 11:16 pm

Re: NaN value on NewtonBody Position

Postby Julio Jerez » Thu Nov 17, 2011 8:08 am

if you can compile the engine in debug mode in linux and the bug still happens, then you can enable this macro
Code: Select all
#if (defined (_WIN_32_VER) || defined (_WIN_64_VER))
   #ifdef _DEBUG
      #define dgCheckFloat(x) _finite(x)
   #else
      #define dgCheckFloat(x) true
   #endif
#else
   #define dgCheckFloat(x) true
#endif


if is in file
...\source\core\dgTypes.h

an as you can see it is only defined for windows, you can find the equivalent for isNam of is _finite in the versionn of GCC you are using,
and the have the function assertingg when the first nam happens. It will show why and where it happens
Julio Jerez
Moderator
Moderator
 
Posts: 12426
Joined: Sun Sep 14, 2003 2:18 pm
Location: Los Angeles

Re: NaN value on NewtonBody Position

Postby KATO2 » Thu Nov 17, 2011 9:04 am

ok, i will try it.
KATO2
 
Posts: 23
Joined: Thu Nov 10, 2011 11:16 pm

Re: NaN value on NewtonBody Position

Postby KATO2 » Thu Nov 17, 2011 12:24 pm

i build newton in debug mode, i maked following changes in makefile

this lines:
Code: Select all
DG_SRCS = \
   $(DG_PATH)dg.cpp \
   $(DG_PATH)dgRef.cpp \


changes to:
Code: Select all
DG_SRCS = \
   $(DG_PATH)dg.cpp \
   $(DG_PATH)dgDebug.cpp \
   $(DG_PATH)dgRef.cpp \


The lines:
Code: Select all
CPU_FLAGS = -O2 -fpic -msse -msse2 -ffloat-store -freciprocal-math -funsafe-math-optimizations -fsingle-precision-constant
FLAGS = -c -Wall -Wno-strict-aliasing -D_LINUX_VER $(CPU_FLAGS) -I$(DG_INCLUDED_PATH) -I$(DG_INCLUDED_PHYSICS_PATH)


changes to:
Code: Select all
CPU_FLAGS = -O2 -g -fpic -msse -msse2 -ffloat-store -freciprocal-math -funsafe-math-optimizations -fsingle-precision-constant
FLAGS = -c -Wall -Wno-strict-aliasing -D_LINUX_VER -D_DEBUG $(CPU_FLAGS) -I$(DG_INCLUDED_PATH) -I$(DG_INCLUDED_PHYSICS_PATH)


in dgtypes.h i added the following lines:
Code: Select all
#if (defined (_LINUX_VER) || defined (_MAC_VER))
   #define _isfinite(x)   isfinite(x)
#else
   #if (defined (_WIN_32_VER) || defined (_WIN_64_VER))
      #define _isfinite(x)   _finite(x)
   #else
      #define _isfinite(x)   true
   #endif
#endif


i also change in dgtypes.h the following lines:
Code: Select all
#if (defined (_WIN_32_VER) || defined (_WIN_64_VER))
   #ifdef _DEBUG
      #define dgCheckFloat(x) _finite(x)
   #else
      #define dgCheckFloat(x) true
   #endif
#else
   #define dgCheckFloat(x) true
#endif


by the code below:
Code: Select all
#if (defined (_WIN_32_VER) || defined (_WIN_64_VER) || defined (_LINUX_VER) || defined (_MAC_VER))
   #ifdef _DEBUG
      #define dgCheckFloat(x) _isfinite(x)
   #else
      #define dgCheckFloat(x) true
   #endif
#else
   #define dgCheckFloat(x) true
#endif


In file dgMinkowskiConv.cpp i added following define (i am not sure for MAC_VER).
Code: Select all
#if (defined (_LINUX_VER) || defined (_MAC_VER))
   #define __FUNCDNAME__ __FUNCTION__
#endif


finally, in dgDebug.cpp i add:
Code: Select all
#if (defined (_LINUX_VER) || defined (_MAC_VER))
   #ifdef _DEBUG
   #include <stdarg.h>

   extern "C" {
      void OutputDebugStringA(const char *fmt, ...) {
         va_list args;
         va_start(args, fmt);
         vprintf(fmt, args);
         va_end(args);
      }
   }
   #endif
#endif


later, i ran make and Newton library was buit. now i have to prove it.
KATO2
 
Posts: 23
Joined: Thu Nov 10, 2011 11:16 pm

Re: NaN value on NewtonBody Position

Postby KATO2 » Thu Nov 17, 2011 12:50 pm

Julio. i ran my simulation in debug mode, and the error has happened, but i did not receive any message. what i am doing wrong?
KATO2
 
Posts: 23
Joined: Thu Nov 10, 2011 11:16 pm

Re: NaN value on NewtonBody Position

Postby Julio Jerez » Fri Nov 18, 2011 9:42 am

that is not possible,
all arithemtic operations use the dgvector class, are you usin simd? run in x87 mode os that it use dgVector oprations.
Julio Jerez
Moderator
Moderator
 
Posts: 12426
Joined: Sun Sep 14, 2003 2:18 pm
Location: Los Angeles

Re: NaN value on NewtonBody Position

Postby KATO2 » Fri Nov 18, 2011 2:21 pm

well, i do not have libSIMD in my system, and i definitly has not been included a SIMD library in my code, therefore, i think i'm not using SIMD. but, my processor has his own implementation of SIMD. i have an AMD Turion X2 64, running linux ubuntu 11.04 32 bits.

Has you seen changes that i made to the code? thats is ok? or i am doing anything wrong?
KATO2
 
Posts: 23
Joined: Thu Nov 10, 2011 11:16 pm

Re: NaN value on NewtonBody Position

Postby KATO2 » Fri Nov 18, 2011 2:45 pm

Well i think this not show me the message, because _ASSERTE is not defined for linux only for windows.
KATO2
 
Posts: 23
Joined: Thu Nov 10, 2011 11:16 pm

Re: NaN value on NewtonBody Position

Postby Julio Jerez » Fri Nov 18, 2011 3:15 pm

yes I said replace the windows assert with the Linux assert
it is in file ../coreLibrary_200\source\core\dgTypes.h

#ifndef _WIN32
#define _ASSERTE(x)
#endif

I had only debug the engine in windows. but of you defile _ASSERTE(x) "the linux assrt here"
it will show the error when it happens
Julio Jerez
Moderator
Moderator
 
Posts: 12426
Joined: Sun Sep 14, 2003 2:18 pm
Location: Los Angeles

Re: NaN value on NewtonBody Position

Postby KATO2 » Sat Nov 19, 2011 10:43 am

Julio.

when i define _ASSERTE how:

Code: Select all
#ifdef _LINUX_VER
   #include <assert.h>
   #define _ASSERTE(x) assert(x)
#elif !(defined (_WIN_32_VER) || defined (_WIN_64_VER))
   #define _ASSERTE(x)
#endif


i get following error:
Code: Select all
../../source/physics/dgWorldDynamicUpdate.cpp:1378:4: error: request for member ‘m128_f32’ in ‘tmpAccel’, which is of non-class type ‘__vector(4) float’


when i open dgWorldDynamicUpdate.cpp and go to line 1378, i can see that:
Code: Select all
_ASSERTE (tmpAccel.m128_f32[3] == dgFloat32 (0.0f));


i know that tmpAccel is a simd_type and symd_type was defined how vFloat, but i don't know where is vFloat defined, so, i don't know how this type is structured.
KATO2
 
Posts: 23
Joined: Thu Nov 10, 2011 11:16 pm

Re: NaN value on NewtonBody Position

Postby KATO2 » Sat Nov 19, 2011 11:03 am

ok, i comment the line 1378 in dgWorldDynamicUpdate.cpp and can buid Newton in DEBUG mode witht assert for linux.

When i run the simulation i get following exception:
Code: Select all
physicsdveserver: ../../source/core/dgVector.h:181: dgTemplateVector<T>& dgTemplateVector<T>::operator+=(const dgTemplateVector<T>&) [with T = float]: Assertion `((sizeof ((*this)[0]) == sizeof (float) ? __finitef ((*this)[0]) : sizeof ((*this)[0]) == sizeof (double) ? __finite ((*this)[0]) : __finitel ((*this)[0])) && (sizeof ((*this)[1]) == sizeof (float) ? __finitef ((*this)[1]) : sizeof ((*this)[1]) == sizeof (double) ? __finite ((*this)[1]) : __finitel ((*this)[1])) && (sizeof ((*this)[2]) == sizeof (float) ? __finitef ((*this)[2]) : sizeof ((*this)[2]) == sizeof (double) ? __finite ((*this)[2]) : __finitel ((*this)[2])) && (sizeof ((*this)[3]) == sizeof (float) ? __finitef ((*this)[3]) : sizeof ((*this)[3]) == sizeof (double) ? __finite ((*this)[3]) : __finitel ((*this)[3])))' failed.


i also add two _ASSERTE more in operator+ for dgVector:
Code: Select all
template<class T>
dgTemplateVector<T>& dgTemplateVector<T>::operator+= (const dgTemplateVector<T> &A)
{
   _ASSERTE (dgCheckVector ((*this)));
   _ASSERTE (dgCheckVector ((A)));  ////------> The exception has ocurred here
   m_x += A.m_x;
   m_y += A.m_y;
   m_z += A.m_z;
   _ASSERTE (dgCheckVector ((*this)));

   return *this;
}


and i get following exception:
Code: Select all
physicsdveserver: ../../source/core/dgVector.h:179: dgTemplateVector<T>& dgTemplateVector<T>::operator+=(const dgTemplateVector<T>&) [with T = float]: Assertion `((sizeof ((A)[0]) == sizeof (float) ? __finitef ((A)[0]) : sizeof ((A)[0]) == sizeof (double) ? __finite ((A)[0]) : __finitel ((A)[0])) && (sizeof ((A)[1]) == sizeof (float) ? __finitef ((A)[1]) : sizeof ((A)[1]) == sizeof (double) ? __finite ((A)[1]) : __finitel ((A)[1])) && (sizeof ((A)[2]) == sizeof (float) ? __finitef ((A)[2]) : sizeof ((A)[2]) == sizeof (double) ? __finite ((A)[2]) : __finitel ((A)[2])) && (sizeof ((A)[3]) == sizeof (float) ? __finitef ((A)[3]) : sizeof ((A)[3]) == sizeof (double) ? __finite ((A)[3]) : __finitel ((A)[3])))' failed.


I think the error can be with any sqrt, log, function when you recalculates object position, maybe an value very closest to zero but with negative sign
KATO2
 
Posts: 23
Joined: Thu Nov 10, 2011 11:16 pm

Re: NaN value on NewtonBody Position

Postby Julio Jerez » Sat Nov 19, 2011 12:28 pm

you has an old version of the engine, beccause this statement
_ASSERTE (tmpAccel.m128_f32[3] == dgFloat32 (0.0f));
is inline 1629 not in line 1378

you should sync to SVN to get the latest version so that I can follow what you are doing.
I added a better check fo nan and finite to file dtype.h file

Code: Select all
#ifndef _WIN32
   #ifdef _DEBUG
      #define _ASSERTE(x) assert(x)
   #else
      #define _ASSERTE(x)
   #endif
#endif

#ifdef _DEBUG
   #ifdef _WIN32
      #define dgCheckFloat(x) (_finite(x) && !_isnan(x))
   #else
      #define dgCheckFloat(x) (_isfinite(x) && !_isnan(x))
   #endif
#endif


but you need to get the latest code, there had being tons of fixes.
Julio Jerez
Moderator
Moderator
 
Posts: 12426
Joined: Sun Sep 14, 2003 2:18 pm
Location: Los Angeles

Re: NaN value on NewtonBody Position

Postby Julio Jerez » Sat Nov 19, 2011 12:48 pm

after you sync to the latest SVN, try again and when the assert happens, show me the trace stack to see what function are tringering those asserts?
Julio Jerez
Moderator
Moderator
 
Posts: 12426
Joined: Sun Sep 14, 2003 2:18 pm
Location: Los Angeles

Next

Return to General Discussion

Who is online

Users browsing this forum: No registered users and 2 guests

cron