NewtonJointSetDestructorDoes Not Work[SOLVED]

Report any bugs here and we'll post fixes

Moderators: Sascha Willems, Thomas

NewtonJointSetDestructorDoes Not Work[SOLVED]

Postby MeltingPlastic » Fri Mar 22, 2019 5:18 pm

Hi Julio,

I am trying to use NewtonJointSetDestructor for contact joints so the app can be notified when its about to be deleted. It doesn't look like the function is currently implemented though.
Last edited by MeltingPlastic on Mon Apr 01, 2019 1:55 pm, edited 1 time in total.
MeltingPlastic
 
Posts: 221
Joined: Fri Feb 07, 2014 11:30 pm

Re: NewtonJointSetDestructorDoes Not Work

Postby Julio Jerez » Fri Mar 22, 2019 6:49 pm

are you holding to contact joints? that's a really bad idea.
I believe the material has a on destroy call back that you can set.
Julio Jerez
Moderator
Moderator
 
Posts: 10984
Joined: Sun Sep 14, 2003 2:18 pm
Location: Los Angeles

Re: NewtonJointSetDestructorDoes Not Work

Postby MeltingPlastic » Sat Mar 23, 2019 12:49 pm

The only reason I have a handle to it is because I needed a way to poll whether or not the Joint was currently Active in the main thread.

In my main thread I have a function that "polls" contacts so which in turn sends Urho3D Events to the rest of the engine. There are 3 events: OnCollisionStart, OnContinuedCollision, OnCollisionEnd.

I can't send events directly from the callback because they could be running in a separate thread, so in the callback I save to a list that lives in the main thread and then poll and send events later. In the poll routine I call NewtonJointIsActive(). That's the only call I have. I added it because the callback didn't seem to be called when the joint became inactive. Assuming that the joint was inactive if I didn't get a callback wasn't working for me either.
MeltingPlastic
 
Posts: 221
Joined: Fri Feb 07, 2014 11:30 pm

Re: NewtonJointSetDestructorDoes Not Work

Postby Julio Jerez » Sat Mar 23, 2019 3:20 pm

Oh it see, calling disjoint active outside can definitely crack if the joint was deleted.
Would adding a world level callback like,
OnContactDestroy help?

There is one for collision shapes, so there is not reason why not having one for contacts.

The reason the callback can't be set on the contact is that, contacts and bilateral joints or subclass of joints, but there are on separate branches, contact are handled by a system that can do a lot of re using, so contact are not really destroyed on demand, they have some kind of garbage collecting system.
Julio Jerez
Moderator
Moderator
 
Posts: 10984
Joined: Sun Sep 14, 2003 2:18 pm
Location: Los Angeles

Re: NewtonJointSetDestructorDoes Not Work

Postby Julio Jerez » Sat Mar 23, 2019 3:36 pm

To have the complete system, in should be two callback, and this actually give me a idea for a functionality I want to and for sometime.

Basically it needs at least two function.
OncontactCreate()
OnContactDestroy()

This way in on contact create, you can save a cook with the contact that you can use for when deleting the contact.
Otherwise on contact delete will force you to search for the contact in some data structure and that the last thing you want to do.
If you save a cook, say an index of a node from a list, now you can just get the cook and use to find where the contact is in you database.

The feature I was thinking is the user defined contact generation, I have been found that in an awork way, for for example tires. Contact where cod dies not help.
Julio Jerez
Moderator
Moderator
 
Posts: 10984
Joined: Sun Sep 14, 2003 2:18 pm
Location: Los Angeles

Re: NewtonJointSetDestructorDoes Not Work

Postby Julio Jerez » Sat Mar 23, 2019 6:24 pm

ok the functionality is in
void NewtonWorldSetCreateDestroyContactCallback(const NewtonWorld* const newtonWorld, NewtonCreateContactCallback createContact, NewtonDestroyContactCallback destroyContact);

there is a use case in the sandbox, I will comment out later, but you can see how is works.
Remember this function is for very high performance usage, you should not do much work there because there are ton of contact on flight at any time.

I have not added the way to add user data wit the contacts, which is important for the look Up by I believe this functionality tat is the joint should work I check later.
basically this in create you register some userdata with the contact, that you can use later for find where the contact is in your database.
The idea is to safe for doing a expensive search. doing so end on a quadratic maybe even cubic time complexity cost is you search is anything other than constant time.
Julio Jerez
Moderator
Moderator
 
Posts: 10984
Joined: Sun Sep 14, 2003 2:18 pm
Location: Los Angeles

Re: NewtonJointSetDestructorDoes Not Work

Postby Julio Jerez » Sun Mar 24, 2019 3:16 pm

alright I added the user data registration to the contact create destroy.
you can look at the detail in functions
Code: Select all
void DemoEntityManager::OnCreateContact(const NewtonWorld* const world, NewtonJoint* const contact);
void DemoEntityManager::OnDestroyContact(const NewtonWorld* const world, NewtonJoint* const contact);

file ../applications\demosSandbox\sdkDemos\DemoEntityManager.cpp

this make a constant time registration using a dList container. It is important you use a fast container by this I mean one the us free list based. Most Game engine already has that complex.
Use a plain STL is a big mistake, because it will garment you memory very fast.
if you do not have suc a contatner you can use a dList, which is Bash allocation and is about 10x faster that a plain STL without special allocator.

Also notice the adding deletion is under a critical section, this is important if you are using this form different thread. for example newton running multiple threads, running async or both.

Anyway I believe this functionality is completed now.
Julio Jerez
Moderator
Moderator
 
Posts: 10984
Joined: Sun Sep 14, 2003 2:18 pm
Location: Los Angeles

Re: NewtonJointSetDestructorDoes Not Work

Postby JernejL » Sun Mar 24, 2019 7:02 pm

MeltingPlastic wrote:The only reason I have a handle to it is because I needed a way to poll whether or not the Joint was currently Active in the main thread.

In my main thread I have a function that "polls" contacts so which in turn sends Urho3D Events to the rest of the engine. There are 3 events: OnCollisionStart, OnContinuedCollision, OnCollisionEnd.

I can't send events directly from the callback because they could be running in a separate thread, so in the callback I save to a list that lives in the main thread and then poll and send events later. In the poll routine I call NewtonJointIsActive(). That's the only call I have. I added it because the callback didn't seem to be called when the joint became inactive. Assuming that the joint was inactive if I didn't get a callback wasn't working for me either.


I think you might be better by communicating this differently between threads by sending data if the bodies are in collision each frame update, because i'm not sure that this will work well with what you want to achieve as hit contact joints are probably created on the fly, and each body can have multiple contacts that are created and destroyed at different times, so when you have a callback that one was removed, you will still need to check if any other are still active.
Help improving the Newton Game Dynamics WIKI
User avatar
JernejL
 
Posts: 1451
Joined: Mon Dec 06, 2004 2:00 pm
Location: Slovenia

Re: NewtonJointSetDestructorDoes Not Work

Postby MeltingPlastic » Mon Mar 25, 2019 3:19 pm

Thanks Julio I'll sync when I can and use the new callbacks as well as look at the code in DemoEntityManager.
MeltingPlastic
 
Posts: 221
Joined: Fri Feb 07, 2014 11:30 pm


Return to Bugs and Fixes

Who is online

Users browsing this forum: No registered users and 1 guest