Moving Child of compound object

JohnnyM
Posts: 15
Joined: Tue Dec 23, 2008 11:51 pm

Moving Child of compound object

Post by JohnnyM »

How do you correctly move a child shape of a compound object. Using updateChildTransform() causes a crash.

Thanks,
Johannes M

[Edit] I previously had a question about the seemingly missing btGhostObject.h, but I found it now. It appears the Vista search is just useless (and I did tell it to search through unindexed results).

[Edit] Well i can create a ghost object now, but Visual Studio 2008 doesn't give me any intellisense info, and when I right click on a btGhostObject and try to look at the definition it says the Symbol 'btGhostObject' is not defined. And why wasn't the ghost object included by default? Thanks.
User avatar
Erwin Coumans
Site Admin
Posts: 4221
Joined: Sun Jun 26, 2005 6:43 pm
Location: California, USA

Re: Moving Child of compound object

Post by Erwin Coumans »

JohnnyM wrote:How do you correctly move a child shape of a compound object. Using updateChildTransform() causes a crash.
btCompoundShape::updateChildTransform should not crash. Do you have a full call stack at the moment of the crash (and details about Bullet version, compiler version, build system, platform).

Thanks,
Erwin
JohnnyM
Posts: 15
Joined: Tue Dec 23, 2008 11:51 pm

Re: Moving Child of compound object

Post by JohnnyM »

I have MS Visual C++ 2008 and bullet 2.73 sp1. I'm also using Vista Home Premium 64bit.

The only thing I'm doing in my code is initializing everything, stepping the simulation 400 times and then destroying everything.

There is only a ground plane and two rigid bodies in my scene. I have a sphere and a compound object made up of two spheres.
It explodes on this line of code (I previously called getNumChildShapes() on fallShape2 and it returns 2):
fallShape2->updateChildTransform(1,fallShape2->getChildTransform(1));
I know that line is useless, but I originally tried putting in a custom btTransform I defined. That made it blow up too.

Any idea? Should I post more code?

Thanks
sparkprime
Posts: 508
Joined: Fri May 30, 2008 2:51 am
Location: Ossining, New York

Re: Moving Child of compound object

Post by sparkprime »

It sounds like you have the makings of an ideal reproduction case there so pasting the whole code is a good idea
JohnnyM
Posts: 15
Joined: Tue Dec 23, 2008 11:51 pm

Re: Moving Child of compound object

Post by JohnnyM »

Here's my code.
btDbvtBroadphase* broadphase = new btDbvtBroadphase();
btDefaultCollisionConfiguration* collisionConfiguration = new btDefaultCollisionConfiguration();
btCollisionDispatcher* dispatcher = new btCollisionDispatcher(collisionConfiguration);
btSequentialImpulseConstraintSolver* solver = new btSequentialImpulseConstraintSolver;
dynamicsWorld = new btSoftRigidDynamicsWorld(dispatcher,broadphase,solver,collisionConfiguration);
dynamicsWorld->setGravity(btVector3(0,-10,0));

btCollisionShape* groundShape = new btStaticPlaneShape(btVector3(0,1,0),1);

btCollisionShape* fallShape = new btSphereShape(1);
btCompoundShape* fallShape2 = new btCompoundShape();
fallShape2->addChildShape(btTransform(btQuaternion(0,0,0),btVector3(0,0,0)),fallShape);
fallShape2->addChildShape(btTransform(btQuaternion(0,0,0),btVector3(0,1,0)),fallShape);

btDefaultMotionState* groundMotionState = new btDefaultMotionState(btTransform(btQuaternion(0,0,0,1),btVector3(0,-1,0)));
btRigidBody::btRigidBodyConstructionInfo
groundRigidBodyCI(0,groundMotionState,groundShape,btVector3(0,0,0));
btRigidBody* groundRigidBody = new btRigidBody(groundRigidBodyCI);
dynamicsWorld->addRigidBody(groundRigidBody);

btMotionState* fallMotionState = new btDefaultMotionState(btTransform(btQuaternion(0,0,0,1),btVector3(0,50,0)));
btScalar mass = 100;
btVector3 fallInertia(0,0,0);
fallShape->calculateLocalInertia(mass,fallInertia);
btRigidBody::btRigidBodyConstructionInfo fallRigidBodyCI(mass,fallMotionState,fallShape,fallInertia);
btRigidBody* fallRigidBody = new btRigidBody(fallRigidBodyCI);
fallMotionState = new btDefaultMotionState(btTransform(btQuaternion(0,0,0,1),btVector3(0,50,0)));
mass = 1;
btRigidBody::btRigidBodyConstructionInfo fallRigidBodyCI2(mass,fallMotionState,fallShape2,fallInertia);
btRigidBody* fallRigidBody2 = new btRigidBody(fallRigidBodyCI2);
dynamicsWorld->addRigidBody(fallRigidBody);
dynamicsWorld->addRigidBody(fallRigidBody2);

for (int i=0 ; i<120 ; i++) {

dynamicsWorld->stepSimulation(1/60.f,10);

btTransform asdf;
fallShape2->updateChildTransform(1,asdf); // Blows up here
}
Sorry. It's a bit of a mess.
JohnnyM
Posts: 15
Joined: Tue Dec 23, 2008 11:51 pm

Re: Moving Child of compound object

Post by JohnnyM »

How does the index for Compound objects work, because something must be really weird with them. I assumed that if I had two child objects, the indexes would be 0 and 1. This must not be the case though because when I try to remove child shape by index, it crashes. I can remove the same object by giving it the collision shape though. Also, I am able to modify the child transform by getting the child list and accessing the transform directly.
User avatar
Erwin Coumans
Site Admin
Posts: 4221
Joined: Sun Jun 26, 2005 6:43 pm
Location: California, USA

Re: Moving Child of compound object

Post by Erwin Coumans »

'it crashes' or 'it blows up' doesn't help. Can you please provide a full callstack at the time of the crash. Please google for it, if you don't know what a callstack is.

Code: Select all

btTransform asdf;
fallShape2->updateChildTransform(1,asdf); // Blows up here
asdf is not initialized. Make sure to properly initialize the position and orientation. For example

Code: Select all

btTransform asdf;
asdf.setIdentity();//important
fallShape2->updateChildTransform(1,asdf); // Blows up here
I assumed that if I had two child objects, the indexes would be 0 and 1. This must not be the case though because when I try to remove child shape by index, it crashes.
The indices starts at zero. So if you have 2 child shapes, and remove one, the remaining automatically gets re-assigned index '0'.

Thanks,
Erwin
JohnnyM
Posts: 15
Joined: Tue Dec 23, 2008 11:51 pm

Re: Moving Child of compound object

Post by JohnnyM »

One my of debug dlls is broken or something, so my debug mode won't work. I'm not sure which it is. If i get it working I'll look into my problem here further, but I've managed to work around it for the time being.
vsobkowski
Posts: 2
Joined: Tue Jan 20, 2009 11:56 am

Re: Moving Child of compound object

Post by vsobkowski »

I recently had similar problem.
I had submit issue about this: http://code.google.com/p/bullet/issues/detail?id=184