Newton4 freezing

Report any bugs here and we'll post fixes

Moderators: Sascha Willems, Thomas

Newton4 freezing

Postby Bird » Sun Jan 02, 2022 9:01 pm

Hi Julio,

I think we had this problem before and you solved it but now it seems to be back. When I interactively generate a pile of many geometric instances in a scene Newton4 eventually stops running. Here's a video that shows what I'm doing. Usually Newton freezes after around 300 - 400 instances have been created. While the simulation is running, I am adding the instances to ndWorld->AddBody during the OnPostUpdate() function so that it's on Newton's thread.

https://youtu.be/auC5kGmwNEU
Bird
 
Posts: 623
Joined: Tue Nov 22, 2011 1:27 am

Re: Newton4 freezing

Postby Julio Jerez » Sun Jan 02, 2022 9:05 pm

Please sync again, it was a bug in the background thread.
I think is fix now.
Julio Jerez
Moderator
Moderator
 
Posts: 12249
Joined: Sun Sep 14, 2003 2:18 pm
Location: Los Angeles

Re: Newton4 freezing

Postby Julio Jerez » Sun Jan 02, 2022 9:12 pm

Oh, I see you are adding the in postulate.

Maybe this is a good time to make the deferred add,

I had that on my list of things before the really, but somehow,
I left for after the release.

But in any case, sync and try again. If it still fails, I will make the deferred add so that adding and remove can be done at any time.

I did it for contacts but is has to be bone for all objects. Bodies, Joints and models.

Btw, it is so cool how the pile of rocks comes to such natural looking formation. I love it :mrgreen:
Julio Jerez
Moderator
Moderator
 
Posts: 12249
Joined: Sun Sep 14, 2003 2:18 pm
Location: Los Angeles

Re: Newton4 freezing

Postby Bird » Sun Jan 02, 2022 9:34 pm

I can add more rocks now (over 700 ) in the latest sync but it is still freezing after a while.

Yeah, I'm probably your only user making rock piles. :)

I've made a bunch of other "piles" with Newton to test out the stand alone renderer I had to make since I had to leave LightWave

http://berserko.hurleyworks.com/portfolio-items/cg/
Bird
 
Posts: 623
Joined: Tue Nov 22, 2011 1:27 am

Re: Newton4 freezing

Postby Julio Jerez » Sun Jan 02, 2022 10:31 pm

oh I was going to say that there still could be the same bug, by that cannot be the case since you are not using the new ndThreadBacgroundWorker, unless you made your layer based on

class ndPhysicsWorld

has you?

in any case, I added void CollisionUpdate(ndFloat32 timestep);

I tested it by setting a break point on function
void ndScene::CalculateJointContacts(ndInt32 threadIndex, ndContact* const contact)

line 838:
bool processContacts = m_contactNotifyCallback->OnAabbOverlap(contact, m_timestep);

and some demos get the calls and some do not, but that is how is supposed to work.
for example, demo one, the capsules are too far apart so no call is made.
but demo friction ramp, gets the call because some boxed overlap with the ramp.

please sync and try that.

mean time, can you tell me how you implement your add body function.
where are you making the call from, this will give some idea how to make that modification.
Julio Jerez
Moderator
Moderator
 
Posts: 12249
Joined: Sun Sep 14, 2003 2:18 pm
Location: Los Angeles

Re: Newton4 freezing

Postby Bird » Mon Jan 03, 2022 4:17 pm

No, I am not using class ndPhysicsWorld. I made my own class that inherits from ndWorld and does not use the ndThreadBacgroundWorker.

in any case, I added void CollisionUpdate(ndFloat32 timestep);


Sorry, it is still not working for me. It is only working if the engine is running like your demo scenes are. I need to be able to get contact info when the engine is not running too.

Here's what my update function looks like now. The values for the calculated velocity look like this as I drag a body on the ground. Does these seem reasonable?
18.238883 DEBUG [22732 StringUtil.h->mace::vecStr3f:74] (-1.129153, 0.000000, 1.579649)
18.258926 DEBUG [22732 StringUtil.h->mace::vecStr3f:67] --- called from VELOCITY
18.259144 DEBUG [22732 StringUtil.h->mace::vecStr3f:74] (-0.787382, 0.000000, 1.414289)
18.279462 DEBUG [22732 StringUtil.h->mace::vecStr3f:67] --- called from VELOCITY
18.279676 DEBUG [22732 StringUtil.h->mace::vecStr3f:74] (0.000000, 0.000000, 0.000000)
18.301337 DEBUG [22732 StringUtil.h->mace::vecStr3f:67] --- called from VELOCITY
18.301552 DEBUG [22732 StringUtil.h->mace::vecStr3f:74] (-0.794220, 0.000000, 1.128731)
18.324850 DEBUG [22732 StringUtil.h->mace::vecStr3f:67] --- called from VELOCITY
18.325108 DEBUG [22732 StringUtil.h->mace::vecStr3f:74] (-0.337064, 0.000000, 0.720785)

Code: Select all
void NewtonEngine::updatePoseAndScale (RenderableNode& node)
{
    ndBodyDynamic* const body = static_cast<ndBodyDynamic*> (node->getUserdata());
    if (!body) return;

    ndMatrix currentPose;
    eigenToNewton (node->getSpaceTime().worldTransform, currentPose);
    body->SetMatrix (currentPose);

    ndShapeInstance& shape = body->GetCollisionShape();
    Eigen::Vector3f s = node->getSpaceTime().scale;
    ndVector scale = ndVector (s.x(), s.y(), s.z(), 0.0f);
    shape.SetScale (scale);

    node->getSpaceTime().startScale = s;
    node->getSpaceTime().makeCurrentPoseStartPose();

    // body->veloc = (body->posit - desired position) / timestep
    Eigen::Vector3f previousSpot = node->getSpaceTime().previousWorldTransform.translation();
    Eigen::Vector3f newSpot = node->getSpaceTime().worldTransform.translation();

    ndFloat32 timeStep = (1.0f / 60.0f);
    Eigen::Vector3f v = (previousSpot - newSpot) / timeStep;
   
    ndVector veloc = ndVector (v.x(), v.y(), v.z(), 0.0f);
    body->SetVelocity (veloc);

    state->world->CollisionUpdate (timeStep);
}


mean time, can you tell me how you implement your add body function.
where are you making the call from, this will give some idea how to make that modification.


I'm running Newton on a separate thread. When I add a new body I call this function.

Code: Select all
void NewtonBodyHandler::addBody (RenderableNode& node, PhysicsEngineState engineState)
{
    // if the engine is running, bodies have to be added on Newton's thread
    engineState == PhysicsEngineState::Running ? pendingAdds.enqueue (node) : addBodyToEngine (node);
}



If the engine is running, I add the body to a thread-safe queue and then add to the engine during the ndWorld::OnPostUpdate

Code: Select all
void NewtonBodyHandler::onPostUpdate (ndFloat32 timestep)
{
    while (pendingAdds.size_approx())
    {
        RenderableNode node;
        bool found = pendingAdds.try_dequeue (node);
        if (found)
            addBodyToEngine (node);
    }
}
Bird
 
Posts: 623
Joined: Tue Nov 22, 2011 1:27 am

Re: Newton4 freezing

Postby Julio Jerez » Mon Jan 03, 2022 5:04 pm

ok we are dealing with two problems here.
let us try the Collision Update first.

I will set a demo, this afternoon that will play some object and one will move until the they collide,
and will show the contacts.
them you can look at that for your set up.

let us work on that first.
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 12 guests