NewtonWaitForUpdateToFinish problem

A place to discuss everything related to Newton Dynamics.

Moderators: Sascha Willems, walaber

NewtonWaitForUpdateToFinish problem

Postby JernejL » Mon May 20, 2019 2:02 am

NewtonWaitForUpdateToFinish doesn't seem to work in latest build anymore.

When i call NewtonWaitForUpdateToFinish it seems like i get callbacks called after that, if i replace call with just NewtonUpdate, everything starts to work properly again - that is, all callbacks are done within that call.

I tested this by setting a global variable before calling NewtonUpdateAsync and un-setting it after NewtonWaitForUpdateToFinish, i put assert into transform callback and it shows it being called after NewtonWaitForUpdateToFinish, and this breaks a lot of thread-unsafe variables that rely on newton calls being between newton async + wait calls, and as consequence gives me very strange data corruption problems.
Help improving the Newton Game Dynamics WIKI
User avatar
JernejL
 
Posts: 1578
Joined: Mon Dec 06, 2004 2:00 pm
Location: Slovenia

Re: NewtonWaitForUpdateToFinish problem

Postby Julio Jerez » Mon May 20, 2019 8:23 am

That would be a really bad bug. I have not touched that in a long time.

can you edit the test demo we're I put you mesh to reproduce the problem.

Edit:
Actually I will add that test to the sandbox this way it will show if it happens on any demo.
Julio Jerez
Moderator
Moderator
 
Posts: 12249
Joined: Sun Sep 14, 2003 2:18 pm
Location: Los Angeles

Re: NewtonWaitForUpdateToFinish problem

Postby JernejL » Mon May 20, 2019 1:17 pm

My test case is pretty simple.

Just set a true / false flag before NewtonUpdateAsync and clear it after NewtonWaitForUpdateToFinish, then check it in your transform callbacks.

Also a question: when is continous collision coming back? i have really big problems with bodies tunneling due to this that did not happen in previous versions of newton :(
Help improving the Newton Game Dynamics WIKI
User avatar
JernejL
 
Posts: 1578
Joined: Mon Dec 06, 2004 2:00 pm
Location: Slovenia

Re: NewtonWaitForUpdateToFinish problem

Postby Julio Jerez » Mon May 20, 2019 1:42 pm

I am adding that sync check to the engine side.

then let us see about the CCD.
Julio Jerez
Moderator
Moderator
 
Posts: 12249
Joined: Sun Sep 14, 2003 2:18 pm
Location: Los Angeles

Re: NewtonWaitForUpdateToFinish problem

Postby JernejL » Mon May 20, 2019 2:04 pm

Here is a video showing NewtonWaitForUpdateToFinish bug:

https://www.youtube.com/watch?v=Y8vzvD0I-h0

Please note.. call stack is broken in lazarus (and shows all newton functions as "newtoncollisionaggregateselfcollision" ), because it does not work well with PDB symbols.
Help improving the Newton Game Dynamics WIKI
User avatar
JernejL
 
Posts: 1578
Joined: Mon Dec 06, 2004 2:00 pm
Location: Slovenia

Re: NewtonWaitForUpdateToFinish problem

Postby Julio Jerez » Mon May 20, 2019 2:22 pm

I can't really read the text is too burry, and is set to highest quality 480 already.

I added the check to make sure is working as expected from the low level.
the check is here: file ../sdk\dgPhysics\dgWorld.cpp line 965
dgAssert(m_testAsynUpdate);

please sync and see if the sdk assert on your, I tested and seem to be fine with the sandbox.
My guess is that you are misusing it. but first les us see if the SDK assert.
Julio Jerez
Moderator
Moderator
 
Posts: 12249
Joined: Sun Sep 14, 2003 2:18 pm
Location: Los Angeles

Re: NewtonWaitForUpdateToFinish problem

Postby JernejL » Mon May 20, 2019 2:52 pm

It's impractical to use debug compiled newton because there are so many other asserts that are triggered that are still in the code that i'd need to remove first (an example of assert that is unneccesary is dgAssert in NewtonMaterialSetContactNormalAcceleration function).

I'm not sure what youtube did to the video but it made it awful.. i'll try to make another one later without remote desktop involved :/

My setup is as following:

Code: Select all
                in_update:= true;

                //NewtonUpdate(Newton_ext.NWorld, 0.1 / 6);

                NewtonUpdateAsync(Newton_ext.NWorld, 0.1 / 6);
                NewtonWaitForUpdateToFinish(Newton_ext.NWorld); // sync physics thread

                in_update:= false;


in my forcetorque and transform callbacks i check in_update value with assert, and if i use NewtonUpdateAsync + NewtonWaitForUpdateToFinish the assert is triggering, indicating that callbacks were triggered after NewtonWaitForUpdateToFinish.
Help improving the Newton Game Dynamics WIKI
User avatar
JernejL
 
Posts: 1578
Joined: Mon Dec 06, 2004 2:00 pm
Location: Slovenia

Re: NewtonWaitForUpdateToFinish problem

Postby Dave Gravel » Mon May 20, 2019 3:01 pm

You can build the debug dll with this flag DG_DISABLE_ASSERT for remove the assert in debug mode.
It is not good for all situations but maybe it can help you for debug from pascal side.
You search a nice physics solution, if you can read this message you're at the good place :wink:
OrionX3D Projects & Demos:
https://orionx3d.sytes.net
https://www.facebook.com/dave.gravel1
https://www.youtube.com/user/EvadLevarg/videos
User avatar
Dave Gravel
 
Posts: 800
Joined: Sat Apr 01, 2006 9:31 pm
Location: Quebec in Canada.

Re: NewtonWaitForUpdateToFinish problem

Postby Julio Jerez » Mon May 20, 2019 3:11 pm

JernejL wrote:It's impractical to use debug compiled newton because there are so many other asserts that are triggered that are still in the code that i'd need to remove first
(an example of assert that is unneccesary is dgAssert in NewtonMaterialSetContactNormalAcceleration function).

the asserts are a sign something is not quite right. yes some are unnecessary but I added them because at the time I did not have a way to test the functionality.
I removed that one below.
Code: Select all
void NewtonMaterialSetContactNormalAcceleration(const NewtonMaterial* const materialHandle, dFloat accel)
{
   TRACE_FUNCTION(__FUNCTION__);
   dgContactMaterial* const material = (dgContactMaterial*) materialHandle;
   dgAssert(0);
   material->m_normal_Force.m_force = accel;
   material->m_flags |= dgContactMaterial::m_overrideNormalAccel;
}


JernejL wrote:in my forcetorque and transform callbacks i check in_update value with assert, and if i use NewtonUpdateAsync + NewtonWaitForUpdateToFinish the assert is triggering, indicating that callbacks were triggered after NewtonWaitForUpdateToFinish.

what variable is in_update?
the one added is called dgAssert(m_testAsynUpdate);
please sync again let us see if we can clear the assert, I can run most the time in debug without assert triggering, you should be able to do the same.
Julio Jerez
Moderator
Moderator
 
Posts: 12249
Joined: Sun Sep 14, 2003 2:18 pm
Location: Los Angeles

Re: NewtonWaitForUpdateToFinish problem

Postby Julio Jerez » Mon May 20, 2019 3:18 pm

I assume you meant 1.0/60.0
I will add the same set up to the sandbox demo and see if I reproduce the same bug.
Code: Select all
in_update:= true;
                //NewtonUpdate(Newton_ext.NWorld, 0.1 / 6);

                NewtonUpdateAsync(Newton_ext.NWorld, 0.1 / 6);
                NewtonWaitForUpdateToFinish(Newton_ext.NWorld); // sync physics thread

                in_update:= false;


but I am not trying to be pedantry, the asserts are important.
Julio Jerez
Moderator
Moderator
 
Posts: 12249
Joined: Sun Sep 14, 2003 2:18 pm
Location: Los Angeles

Re: NewtonWaitForUpdateToFinish problem

Postby Julio Jerez » Mon May 20, 2019 3:45 pm

I just added your test and you are right the assert happen the force and torque callback.
It seems it should not but is does.
I am debugging it.
Julio Jerez
Moderator
Moderator
 
Posts: 12249
Joined: Sun Sep 14, 2003 2:18 pm
Location: Los Angeles

Re: NewtonWaitForUpdateToFinish problem

Postby JernejL » Mon May 20, 2019 4:18 pm

Glad to be able to help finding bugs :) let me know when a patch is made for this so i can re-compile newton dll and re-test.
Help improving the Newton Game Dynamics WIKI
User avatar
JernejL
 
Posts: 1578
Joined: Mon Dec 06, 2004 2:00 pm
Location: Slovenia

Re: NewtonWaitForUpdateToFinish problem

Postby Julio Jerez » Tue May 21, 2019 10:07 am

actually this broke about a year ago when I try to make the Engine thread work in both mode synchronous and asynchronous. that's always a big mistake. Ii added too much complexity to the state machine logic and in the end it do not work.

I re stated the old synchronous thread and for the time been I made the Async update call teh SynUpdate this make the system work, and late tonight I will add the AsyncThread.
Please sync when you have time and tell my is thsi work, even is not Async it just pretend it is.

This also allows us to address teh continues collsion problem.
Julio Jerez
Moderator
Moderator
 
Posts: 12249
Joined: Sun Sep 14, 2003 2:18 pm
Location: Los Angeles

Re: NewtonWaitForUpdateToFinish problem

Postby JernejL » Wed May 22, 2019 6:55 am

Ok, i've synced it and now it works well - no more asserts.

I can now make tests with continous collision when you have fixes ready :)
Help improving the Newton Game Dynamics WIKI
User avatar
JernejL
 
Posts: 1578
Joined: Mon Dec 06, 2004 2:00 pm
Location: Slovenia

Re: NewtonWaitForUpdateToFinish problem

Postby Julio Jerez » Wed May 22, 2019 1:28 pm

if you sync before this morning please do it again, I committed the Async functionality late last night.
I tested and worked fine here.
also on this: //NewtonUpdate(Newton_ext.NWorld, 0.1 / 6);

I assume you mean //NewtonUpdate(Newton_ext.NWorld, 0.1 / 60.0f);

also of the CCD, here si oen thong you can do that will make the entire Game work much mich better
no just the CCD. if you are no doing it already, but I believe your aren't
after you create the newton word call function NewtonSetNumberOfSubsteps like this

Code: Select all
   // create the newton world
   m_world = NewtonCreate();

   // set the number of sub steps
   NewtonSetNumberOfSubsteps (m_world, 2;


The improvement is quite dramatic and the cost is marginal.
in you case you can even try 3,

please try that and tell how it goes.
Julio Jerez
Moderator
Moderator
 
Posts: 12249
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 14 guests

cron