I just updated to the latest version of Newton and I'm having some stability problems. When I create a new NewtonBody, I save it's pointer in my own graphics object so I can access it later.
- Code: Select all
void NewtonBodyHandler::addBodyToEngine(RenderableNode& node)
{
NewtonBody * const newtonBody = ops.createRigidBody(node, startPose, collision);
NewtonBodySetUserData(newtonBody, node.get());
node->setUserData(static_cast<NewtonBody*>(newtonBody));
}
Later when I try to use the NewtonBody pointer that I saved, any Newton function I call with it is corrupt.
- Code: Select all
NewtonCollision * NewtonOps::createCollisionShape(RenderableNode& node)
{
if (node->isInstance())
{
RenderableNode from = node->getInstancedFrom();
NewtonBody * const newtonBody = static_cast<NewtonBody*>(from->getUserdata());
return NewtonBodyGetCollision(newtonBody);
}
}
If I debug the NewtonBodyGetCollision(newtonBody) call I can see the passed in NewtonBody pointer is filled with garbage. I can workaround the problem by iterating through the all the NewtonBodies but I'd rather not have to do that if possible
- Code: Select all
// find the NewtonBody for the instanced from node the hard way
for (NewtonBody* body = NewtonWorldGetFirstBody(world); body; body = NewtonWorldGetNextBody(world, body))
{
Renderable* const node = static_cast<Renderable*>(NewtonBodyGetUserData(body));
RenderableNode renderable = node->shared_from_this();
if (renderable->isInstance()) continue;
if (renderable == from)
return NewtonBodyGetCollision(body);
}
My same code worked with previous versions of Newton
Here'a little sim I made with Newton and NVIDIA's Optix7 ray tracing framework
https://www.youtube.com/watch?v=U0WJWECeZjA&feature=youtu.be