Timing and FPS question

A place to discuss everything related to Newton Dynamics.

Moderators: Sascha Willems, walaber

Re: Timing and FPS question

Postby misho » Sat Jul 07, 2018 1:08 pm

Hi Julio and Zak,

Julio Jerez wrote:you mean this
is that is what you are doing, ther mous be something else wrong.

is you make a debug build and step over the function, you will see that from begin to end is no more than a few dozen lines of code, including every thing, certainly less than 100.


Yes, that, and also this (how I create the body and set up mass and inertia):

Code: Select all
   // create a body with given compound collision and mass
   newEntity->nBody = CreateRigidBody (world, newEntity, objectCollision, newEntity->GetGrossMass()); // <- mass parameter. read this from the object data

   // grab the inertia which will be later used to set decreasing mass to the body
   dFloat dummyMass;
   dVector dvInertia;
   NewtonBodyGetMass(newEntity->nBody, &dummyMass, &dvInertia.m_x, &dvInertia.m_y, &dvInertia.m_z);
   newEntity->SetInertia(dvInertia);


It is important to remember that, when I change mass at visual update level (~60 FPS) everything is fine. But when I use the same call on a physics update level (perhaps ~500 fps?) I get a crash.

So, I don't think there is anything wrong with how I set up my scene (body built with compound collision) and the method I am using to decrease the mass. However, it seems as if I am using NewtonBodySetMassMatrix the way it wasn't intended (perhaps too often?).

Also, zak, I am using synchronous version of NewtonUpdate:
Code: Select all
            NewtonUpdate(g_world, timestepInSecunds);

I'm not proficient enough in multithreaded coding - I am simply calling NewtonUpdate the way it was set up in sandbox examples. My app is a DLL with an event loop.

Event loop is calling synchronous version of NewtonUpdate on every iteration (not sure how fast this is iterating, but let's say 500 fps). One of the events is a frame update notification (which happens at ~60fps), where I grab all of the object's positions and rotations, and pass it on to a simulator client for visual display - that is all.
Misho Katulic
CTO, FSX SpacePort
TerraBuilder
www.terrabuilder.com
misho
 
Posts: 673
Joined: Tue May 04, 2010 10:13 am

Re: Timing and FPS question

Postby misho » Sat Jul 07, 2018 1:16 pm

Julio Jerez wrote:is you make a debug build and step over the function, you will see that from begin to end is no more than a few dozen lines of code, including every thing, certainly less than 100.


I agree - but what I will do first is, I will use my rocket sandbox test case from a few months ago and add this functionality to it to see if this is happening there... Perhaps a simpler case will be easier to understand.

This would probably be easy for you to check as well, just grab one of the simple sandbox examples and start calling NewtonBodySetMassMatrix on one of the bodies on the physics update level.
Misho Katulic
CTO, FSX SpacePort
TerraBuilder
www.terrabuilder.com
misho
 
Posts: 673
Joined: Tue May 04, 2010 10:13 am

Re: Timing and FPS question

Postby JoeJ » Sat Jul 07, 2018 1:53 pm

misho wrote:not sure how fast this is iterating, but let's say 500 fps


You should know how often you do the physics update. But also notice the force torque callback will be called multiple times per update.
This is why i suggested a counter to measure how often you do those mass changes per second - even a light weight function will slow down if you call it MUCH too often. (I remember you used some timelapse stuff - maybe some bug there causes too much updates.)

No idea about the crashes, i don't know if it's ok to change mass in force torque callback :?:
User avatar
JoeJ
 
Posts: 1453
Joined: Tue Dec 21, 2010 6:18 pm

Re: Timing and FPS question

Postby Julio Jerez » Sat Jul 07, 2018 2:14 pm

Ok, let us go one problem at at time. Let us address the crash first.
When Michio suggested to place a call to the function from within an update in the sandbox, it click on me why the crash happens.
Yes you are correct it will lead to a crash even in a thread emulation.
This is a legacy from newton 1.00
Basically to separate the bodies between static and dynamic, the body lust add static bodies from the top and dynamic bodies from the end.
Then if a function changes the mass of a body, it takes the node and move to either the front or the end,
If you are calling the function from and update, I'd the update is from and iterator over that list, it will at some point make the iterator invalid unveknown to the caller.
This has changed from a long time, and the is not reason to keep the list sorted anymore.

I will make that change later so that you can try again, I am not in the computer now.

That call should be made from an update without any problems.
Had you made from a listener it would work, and the bug wuoldcstill be tgere, so that is good.

Let us do that and have the function call from and update, them we can profile it.
Julio Jerez
Moderator
Moderator
 
Posts: 12249
Joined: Sun Sep 14, 2003 2:18 pm
Location: Los Angeles

Re: Timing and FPS question

Postby misho » Sat Jul 07, 2018 2:31 pm

Excellent, sounds good! Let me know when you update the change and I will download the latest.

I do have a static body there (big concrete launch pad) so I should insert a check to avoid processing static bodies.

In what state are the sandbox demos? Last I updated (early April) none of the vehicle demos worked...
Misho Katulic
CTO, FSX SpacePort
TerraBuilder
www.terrabuilder.com
misho
 
Posts: 673
Joined: Tue May 04, 2010 10:13 am

Re: Timing and FPS question

Postby Julio Jerez » Sat Jul 07, 2018 3:58 pm

ok I added a partial fix, until I am complete sure this arrangement is completely unnecessary.
It should work fine for you are long as you do not chnge a body form dynamics (no zero mass ) to static or vise verse.
not you should not check avoiding processing static bodies in order to mak ethe SDK happy.
but that should be good prgramming pratice, for yor own application.

plase sync and try place the fundtion in the newto update, (force and trque or whatever othe funtion you had it before)
this will allow for comparing profiles captures when I get the profile visualizer is a useable state, hopefully this weekend.
Julio Jerez
Moderator
Moderator
 
Posts: 12249
Joined: Sun Sep 14, 2003 2:18 pm
Location: Los Angeles

Re: Timing and FPS question

Postby misho » Sat Jul 21, 2018 1:03 pm

Ok, I hate whining :mrgreen: , but this is why I dread upgrading to the newest version.
There is always some obscure conflict that is resulting from small changes and shifts in Newton core library. This time, I'm getting:

Code: Select all
dgCore.lib(dgProfiler.obj) : error LNK2001: unresolved external symbol "__declspec(dllimport) void __cdecl ttStartRecording(char const * const)" (__imp_?ttStartRecording@@YAXQBD@Z)


(and 5 other similar conflicts from the 6 functions in dTimeTracker.h)... I see that dTimeTracker structure has changed somewhat from the last (April) version I had. I recompiled Newton, compiles fine, but my project, when trying to compile, gives me the above error. I adjusted the new include paths for dProfiler, even kept old dgTimeTracker path even though it is gone and the demosSandbox is still referencing it.

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

Re: Timing and FPS question

Postby JoeJ » Sat Jul 21, 2018 1:14 pm

Guess it's this:

if is on file:
…//newton-dynamics\sdk\dgCore\dgProfiler.h

by commenting of uncommenting out define _DG_USE_PROFILER traces can be enabled of disable.
for now is disabled.
User avatar
JoeJ
 
Posts: 1453
Joined: Tue Dec 21, 2010 6:18 pm

Re: Timing and FPS question

Postby misho » Sat Jul 21, 2018 1:49 pm

THANK YOU JoeJ! That did it! (it was ENABLED) This is now in my "upgrade" notes that I religiously follow, so that I don't whine again :mrgreen:

And now, I am happy to report that Julio's "mod" worked!! My mass-change call is happily working within Physics update loop, without any FPS hit! :D

Julio - as I understand, you mentioned this was a temporary fix and you will do something more permanent over the next few weekends. Have you had a chance to do it? Absolutely no rush on this, I have a build from July 7th.

Also, can the stuff in this post be looked at and addressed? I have to change this manually every time I upgrade, plus, I have to revert to the old dMatrix::GetEulerAngles function that handles all the permutations mentioned in the above forum topic.

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

Re: Timing and FPS question

Postby Julio Jerez » Sat Jul 21, 2018 7:52 pm

misho wrote:And now, I am happy to report that Julio's "mod" worked!! My mass-change call is happily working within Physics update loop, without any FPS hit! :D

Julio - as I understand, you mentioned this was a temporary fix and you will do something more permanent over the next few weekends. Have you had a chance to do it? Absolutely no rush on this, I have a build from July 7th.

what was the mod can you remind me?

edit:
Oh I remember, the change was that the engine uses a trick to keep bodies ordered.
basically the body manage is a link list, in which static bodies are added to the top,
and dynamics bodies are added for the back.

the function set mass removed the body from the list and re added based the new mass value, this was what caused the crash, it was possible that the callback may end up with an invalid list node.

I added a modification that if set mass function do not change a body from dynamics to static, then it does not has to recycle the node, therefore it will work as along ad a body does not changes from dynamics to static or vise verse.

This is a temporary because the mater list will be removed and the engine will not longer need bodies grouped as dynamics and static, it will be later and is anything will make the fix more robust and permanent.
Julio Jerez
Moderator
Moderator
 
Posts: 12249
Joined: Sun Sep 14, 2003 2:18 pm
Location: Los Angeles

Re: Timing and FPS question

Postby misho » Mon Jul 23, 2018 2:04 am

Julio Jerez wrote:This is a temporary because the mater list will be removed and the engine will not longer need bodies grouped as dynamics and static, it will be later and is anything will make the fix more robust and permanent.


Sounds good, Julio!

Also, can the stuff in this post be looked at and addressed? I have to change this manually every time I upgrade, plus, I have to revert to the old dMatrix::GetEulerAngles function that handles all the permutations mentioned in the above forum topic.
Misho Katulic
CTO, FSX SpacePort
TerraBuilder
www.terrabuilder.com
misho
 
Posts: 673
Joined: Tue May 04, 2010 10:13 am

Re: Timing and FPS question

Postby Julio Jerez » Mon Jul 23, 2018 12:00 pm

The problem with the generic decomposition is that it does not let us determine both set of angles.
Each matrix has two different set of eulrrs that generate the same matrix, but to get the two possible set the function must use atan not asin.
The general uses asin and will have to be re write in term of atan generate the two answer.
As an analogy thing a function that caculter the root of a square functions. We know each square function has two roots, but if you solver does not use that knowledge, it is not wrong, it is just I completed.

I see if I can restored the old one later, but if it takes long maybe is best to add another define that generated the order you are using.
What order Euler you use?
Julio Jerez
Moderator
Moderator
 
Posts: 12249
Joined: Sun Sep 14, 2003 2:18 pm
Location: Los Angeles

Re: Timing and FPS question

Postby misho » Mon Jul 23, 2018 12:14 pm

Hi Julio,

As I mentioned in the post, I have to override the current function dMatrix::GetEulerAngles(), which has a case-block statement for only two cases, with a year-old one, which has:

Code: Select all
   int a0 = (order>>8)&3;
   int a1 = (order>>4)&3;
   int a2 = (order>>0)&3;


In my case, I have to use YPR (yaw pitch roll) and RPY (roll pitch yaw) permutations. For this, I also add a full set of permutations:

Code: Select all
enum dEulerAngleOrder
{
   m_pitchYawRoll,
   m_pitchRollYaw,
   PYR = (0 << 8) + (1 << 4) + (2 << 0),
   PRY = (0 << 8) + (2 << 4) + (1 << 0),
   RYP = (2 << 8) + (1 << 4) + (0 << 0),
   RPY = (2 << 8) + (0 << 4) + (1 << 0),
   YPR = (1 << 8) + (0 << 4) + (2 << 0),
   YRP = (1 << 8) + (2 << 4) + (0 << 0)
};


which, when used with a0,a1,a2 parameters (instead of case-block statements) works for me.

All I was wondering is, is it possible to include all 6 permutations, whichever way you need to implement it (a0,a1,a2 parameters or case-block statements).

Including all 6 permutations makes sense because it would make Newton compatible with a wide variety of coordinate systems.
Misho Katulic
CTO, FSX SpacePort
TerraBuilder
www.terrabuilder.com
misho
 
Posts: 673
Joined: Tue May 04, 2010 10:13 am

Re: Timing and FPS question

Postby Julio Jerez » Mon Jul 23, 2018 5:52 pm

Oh yes that's a very cool trick, I will do tonight.
Code: Select all
enum dEulerAngleOrder
{
   m_pitchYawRoll,
   m_pitchRollYaw,
   PYR = (0 << 8) + (1 << 4) + (2 << 0),
   PRY = (0 << 8) + (2 << 4) + (1 << 0),
   RYP = (2 << 8) + (1 << 4) + (0 << 0),
   RPY = (2 << 8) + (0 << 4) + (1 << 0),
   YPR = (1 << 8) + (0 << 4) + (2 << 0),
   YRP = (1 << 8) + (2 << 4) + (0 << 0)
};
Julio Jerez
Moderator
Moderator
 
Posts: 12249
Joined: Sun Sep 14, 2003 2:18 pm
Location: Los Angeles

Re: Timing and FPS question

Postby misho » Tue Jul 24, 2018 11:53 am

Julio Jerez wrote:Oh yes that's a very cool trick, I will do tonight.


That's awesome Julio! Will you also implement the rest of the permutations in dMatrix::GetEulerAngles()?
Misho Katulic
CTO, FSX SpacePort
TerraBuilder
www.terrabuilder.com
misho
 
Posts: 673
Joined: Tue May 04, 2010 10:13 am

PreviousNext

Return to General Discussion

Who is online

Users browsing this forum: No registered users and 13 guests

cron