Freeze in NewtonUpdate()

Report any bugs here and we'll post fixes

Moderators: Sascha Willems, Thomas

Freeze in NewtonUpdate()

Postby Markus » Wed Jun 08, 2011 10:34 am

Hey,

my application freezes often when having a few boxes (<100) on a simple tree collision. It works fine, until suddenly NewtonUpdate() doesn't return. (I'm using Linux, I will try it on Windows tomorrow)

These are the Newton settings:
Code: Select all
   NewtonSetPlatformArchitecture(m_world, 3);
   NewtonSetSolverModel(m_world, 1);
   NewtonSetFrictionModel(m_world, 1);
   NewtonSetThreadsCount(m_world, 2);
   NewtonSetMultiThreadSolverOnSingleIsland(m_world, 0);


This is the stack trace:

Code: Select all
Unknown name [i1]   
   Thread [9] 6441 (Suspended : Container)   
      dgBody::IntegrateVelocity() at coreLibrary_200/source/physics/dgBody.cpp:574     
      dgWorldDynamicUpdate::IntegrateArray() at coreLibrary_200/source/physics/dgWorldDynamicUpdate.cpp:1,026     
      dgSolverWorlkerThreads::ThreadExecute() at coreLibrary_200/source/physics/dgWorldDynamicUpdate.cpp:321     
      dgThreads::DoWork() at coreLibrary_200/source/core/dgThreads.cpp:441     
      dgThreads::ThreadExecute() at coreLibrary_200/source/core/dgThreads.cpp:373     
      start_thread() at 0xb6c9ecc9   
      clone() at 0xb6d8369e   
   Thread [8] 6440 (Suspended : Container)   
      __kernel_vsyscall() at 0xb7fe1424   
      sched_yield() at 0xb6d588ec   
      dgThreadYield() at coreLibrary_200/source/core/dgThreads.cpp:35     
      dgThreads::GetWork() at coreLibrary_200/source/core/dgThreads.cpp:399     
      dgThreads::DoWork() at coreLibrary_200/source/core/dgThreads.cpp:440     
      dgThreads::ThreadExecute() at coreLibrary_200/source/core/dgThreads.cpp:373     
      start_thread() at 0xb6c9ecc9   
      clone() at 0xb6d8369e   
   Thread [5] 6437 (Suspended : Container)   
      __kernel_vsyscall() at 0xb7fe1424   
      nanosleep() at 0xb6d4c1a6   
      RTThreadSleep() at 0xb4acfcf4   
      0xb4a97367   
      rtThreadMain() at 0xb4ad0cd0   
      0xb4acfae7   
      start_thread() at 0xb6c9ecc9   
      clone() at 0xb6d8369e   
   Thread [2] 6432 (Suspended : Container)   
      __kernel_vsyscall() at 0xb7fe1424   
      poll() at 0xb6d74df6   
      g_poll() at 0xb6b80a1b   
      0xb6b7343c   
      g_main_loop_run() at 0xb6b73ba7   
      0xb63c89c4   
      0xb6b9a48f   
      start_thread() at 0xb6c9ecc9   
      clone() at 0xb6d8369e   
   Thread [1] 6429 (Suspended : Signal)   
      __kernel_vsyscall() at 0xb7fe1424   
      sched_yield() at 0xb6d588ec   
      dgThreadYield() at coreLibrary_200/source/core/dgThreads.cpp:35     
      dgThreads::SynchronizationBarrier() at coreLibrary_200/source/core/dgThreads.cpp:467     
      dgWorldDynamicUpdate::UpdateDynamics() at coreLibrary_200/source/physics/dgWorldDynamicUpdate.cpp:210     
      dgWorld::Update() at coreLibrary_200/source/physics/dgWorld.cpp:677     
      Newton::UpdatePhysics() at coreLibrary_200/source/newton/NewtonClass.cpp:112     
      NewtonUpdate() at coreLibrary_200/source/newton/Newton.cpp:717     
      sim::Simulation::update() at src/simulation/Simulation.cpp:640     
      Render::paintGL() at src/gui/render.cpp:101     
      <...more frames...>   


I hope this helps you a bit.

Edit: Of course, this does not happen when using only one Newton thread.
Markus
 
Posts: 52
Joined: Sat Mar 19, 2011 6:31 am

Re: Freeze in NewtonUpdate()

Postby Markus » Wed Jul 20, 2011 11:49 am

I think I may have the solution to this problem:

In dgBody.cpp:572 dgBody::IntegrateVelocity()
Code: Select all
   m_globalCentreOfMass += m_veloc.Scale (timestep);

   while (((m_omega % m_omega) * timestep * timestep) > (DG_MAX_ANGLE_STEP * DG_MAX_ANGLE_STEP)) {

      m_omega = m_omega.Scale (dgFloat32 (0.8f));

   }


You scale m_omega until the while-expression returns true. Now, in my case all components of m_omega are NaN (not a number). This results in a never-ending loop and my program freezes.

I didn't know what the problem was an actually suspected my math library would return wrong values... But this seems to be unlikely, because the same level sometimes works and sometimes causes Newton to freeze. Now I recompilied Newton (on Linux32) with:

Code: Select all
# previous:
# CPU_FLAGS = -O2 -fpic -msse -msse2 -ffloat-store -ffast-math -freciprocal-math -funsafe-math-optimizations -fsingle-precision-constant
# now:
CPU_FLAGS = -O2 -fpic -msse -msse2 -ffloat-store


And now everything seems to work... one of "-ffast-math -freciprocal-math -funsafe-math-optimizations -fsingle-precision-constant" is (probably) causing the problem. I cannot be 100% sure, but I didn't have a freeze after I recompiled.

Since this problem occurs on mutiple PCs (I tested it on some others, mostly Laptops with Linux, including Ubuntu 10.04, 10.10 and Arch Linux) you maybe should think about removing these flags from the makefile.
Markus
 
Posts: 52
Joined: Sat Mar 19, 2011 6:31 am

Re: Freeze in NewtonUpdate()

Postby Julio Jerez » Wed Jul 20, 2011 1:29 pm

tise flags -ffloat-store -ffast-math make the linux version significanly faster.
without then it is just like visual studio.

I'd seen these Nans problems some time, but I do not think it is because the flags: -ffloat-store -ffast-math.
my suggestion is to add a Is Nam() check to the places where Omega is changed to see what is causing it.

I believe that -O2 -fpic -msse -msse2 -ffloat-store -ffast-math are a very good set of flags,

I belive the problem is -Fast-unsafemath because it is too aggresive and brakes ansi C rules
Julio Jerez
Moderator
Moderator
 
Posts: 12249
Joined: Sun Sep 14, 2003 2:18 pm
Location: Los Angeles

Re: Freeze in NewtonUpdate()

Postby Markus » Wed Jul 20, 2011 2:29 pm

I cannot confirm this. I just tried it with "-O2 -g -fpic -msse -msse2 -ffloat-store -ffast-math" and the program freezes (sometimes). The gcc documentation says:

-ffast-math
Sets -fno-math-errno, -funsafe-math-optimizations,
-ffinite-math-only, -fno-rounding-math, -fno-signaling-nans and
-fcx-limited-range.
This option causes the preprocessor macro "__FAST_MATH__" to be
defined.

This option is not turned on by any -O option since it can result
in incorrect output for programs which depend on an exact
implementation of IEEE or ISO rules/specifications for math
functions. It may, however, yield faster code for programs that do
not require the guarantees of these specifications.


Edit:
CPU_FLAGS = -O2 -fpic -msse -msse2 -ffloat-store -freciprocal-math -funsafe-math-optimizations -fsingle-precision-constant
(without -ffast-math) seems to work, too. So -ffast-math is the problem?!
Markus
 
Posts: 52
Joined: Sat Mar 19, 2011 6:31 am

Re: Freeze in NewtonUpdate()

Postby Julio Jerez » Wed Jul 20, 2011 7:48 pm

so -ffast-math off?

Ok I will check the make file without it.
Julio Jerez
Moderator
Moderator
 
Posts: 12249
Joined: Sun Sep 14, 2003 2:18 pm
Location: Los Angeles

Re: Freeze in NewtonUpdate()

Postby Markus » Thu Jul 21, 2011 9:12 am

so -ffast-math off?


Yes, I think so; all other options seem to work.
Markus
 
Posts: 52
Joined: Sat Mar 19, 2011 6:31 am

Re: Freeze in NewtonUpdate()

Postby KATO2 » Tue Nov 15, 2011 3:22 pm

I had the same problem, I remove ffast-math option as you suggest and everything works fine.

The problem now, is what for some bodies, position gives nan values. ​​I read in another thread, and they says that the problem is when a convexhull collides with an treecollision. Julio, could you tell me if there is already a solution to this bug?

Thank you.
KATO2
 
Posts: 23
Joined: Thu Nov 10, 2011 11:16 pm

Re: Freeze in NewtonUpdate()

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

teh make file was check in with out that option.
can you build it is debug?
Julio Jerez
Moderator
Moderator
 
Posts: 12249
Joined: Sun Sep 14, 2003 2:18 pm
Location: Los Angeles

Re: Freeze in NewtonUpdate()

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

yes, i buid it in debug mode and run program, but i obtain same result. what i can do to debug newton and detect problem? i am using Newton with OgreNewt in a server application, but i don't render anything in this side. render is done on the client side.

previously the simulation ran on the client side, and i didn't had this problems, even with precompiled sdk, when i change the simultation to server side, the problems started.
KATO2
 
Posts: 23
Joined: Thu Nov 10, 2011 11:16 pm

Re: Freeze in NewtonUpdate()

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

if you can compile the engine in debug mode in linux and the bug still happens 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
as you can see it is only defined for windows, you can find eh equvalen for isNam of is finite in teh veriosn of GCC you are using and the
have the funtion asstring whn eteh fist nam happne and you will see why it happens and where
Julio Jerez
Moderator
Moderator
 
Posts: 12249
Joined: Sun Sep 14, 2003 2:18 pm
Location: Los Angeles


Return to Bugs and Fixes

Who is online

Users browsing this forum: No registered users and 6 guests