dCustomJoints library and allocation/deallocation interface

A place to discuss everything related to Newton Dynamics.

Moderators: Sascha Willems, walaber

dCustomJoints library and allocation/deallocation interface

Postby godlike » Sun Jan 15, 2017 12:58 pm

I've decided to start using the dCustomJoints library to leverage the work done there. Unfortunately I run into some problems.

What I wanted is to use CustomPlayerControllerManager and since I always use my internal memory allocators I did something like this:
Code: Select all
CustomPlayerControllerManager* myController = myAllocator.newInstance<CustomPlayerControllerManager>()


And this to delete:
Code: Select all
 myAllocator.deleteInstance(myController);


Apparently that won't work for two reasons. The controllers somehow register themselves for automatic deletion when NewtonWorld gets destroyed (why?). Also it's expected to allocate them using operator new and not custom stuff.

I had to track the allocations/deallocations to understand why my app was crashing on shutdown. The custom controller interface is confusing because it allows me to allocate the controller myself and delete it.

I'm not yet sure what is the correct way to solve this interface issue yet.
User avatar
godlike
 
Posts: 58
Joined: Sun Mar 16, 2014 3:48 am

Re: dCustomJoints library and allocation/deallocation interf

Postby Julio Jerez » Sun Jan 15, 2017 4:24 pm

all you need to do is you write you own version of CustomAlloc
this is what the are now.
Code: Select all
void* CustomAlloc::operator new (size_t size)
{
   return NewtonAlloc(int (size));
}

void CustomAlloc::operator delete (void* ptr)
{
   NewtonFree(ptr);
}

and they will allocate memory using the allocation function pointer that you set when you create the newton worlks. or if you replace the pointe in CustomAlloc they will us ethos function pointers.

then you create a classes by sub classing the player controller for example.
Code: Select all
BasicPlayerControllerManager* const playerManager = new BasicPlayerControllerManager (world);
m_controller = playerManager->CreatePlayer(PLAYER_MASS, radius, radius * 0.5f, height, height * 0.33f, playerAxis);
Julio Jerez
Moderator
Moderator
 
Posts: 12249
Joined: Sun Sep 14, 2003 2:18 pm
Location: Los Angeles

Re: dCustomJoints library and allocation/deallocation interf

Postby godlike » Mon Jan 16, 2017 4:29 am

Thanks for the explanation. BTW, should the custom joints classes have the "d" prefix just like the other (dMath, dContainers etc)?
User avatar
godlike
 
Posts: 58
Joined: Sun Mar 16, 2014 3:48 am

Re: dCustomJoints library and allocation/deallocation interf

Postby Julio Jerez » Mon Jan 16, 2017 9:12 am

yes they should, but that was the last system added and but them forget about the naming convention.

by the way the d and dg naming conversion stand for nothing, it is simple a prefix that serve as a king of soft name space to differentiate lower and higher level code.
Julio Jerez
Moderator
Moderator
 
Posts: 12249
Joined: Sun Sep 14, 2003 2:18 pm
Location: Los Angeles


Return to General Discussion

Who is online

Users browsing this forum: No registered users and 20 guests

cron