Soft body update bounds failing

User avatar
dphil
Posts: 237
Joined: Tue Jun 29, 2010 10:27 pm

Soft body update bounds failing

Post by dphil »

I have had rigid body physics working fine for a while in my simulations. Now I am trying to implement soft body dynamics. First, I modified the engine to use the btSoftBodyRigidBodyCollisionConfiguration and btSoftRigidDynamicsWorld. I believe those are the 2 specific things required in the setup to have soft body dynamics.

I tried my best to figure out a basic soft body example from the Bullet demos, and came up with the following code which should create a "soft" cube:

Code: Select all

btSoftBodyWorldInfo	m_softBodyWorldInfo;
	
m_softBodyWorldInfo.air_density		=	(btScalar)1.2;
m_softBodyWorldInfo.water_density	=	0;
m_softBodyWorldInfo.water_offset		=	0;
m_softBodyWorldInfo.water_normal		=	btVector3(0,0,0);
m_softBodyWorldInfo.m_gravity.setValue(0,-10,0);
m_softBodyWorldInfo.m_sparsesdf.Initialize();
m_softBodyWorldInfo.m_dispatcher = dynamicsWorld->getDispatcher();
m_softBodyWorldInfo.m_broadphase = dynamicsWorld->getBroadphase();

const btVector3	c[] = {
        btVector3(-1,-1,-1),
	btVector3(+1,-1,-1),
	btVector3(-1,+1,-1),
	btVector3(+1,+1,-1),
	btVector3(-1,-1,+1),
	btVector3(+1,-1,+1),
	btVector3(-1,+1,+1),
	btVector3(+1,+1,+1)
};

btSoftBody* softCube = btSoftBodyHelpers::CreateFromConvexHull(m_softBodyWorldInfo,c,8);
softCube->generateBendingConstraints(2);

dynamicsWorld->addSoftBody(softCube);
However, whenever I attempt to run the simulation (with just that soft cube and nothing else) it crashes with a generic uninformative "bad access" error that the debugger indicates is in btSoftBody::updateBounds, which is called (by Bullet, not my own code) during the normal stepping of the simulation. I am not able to find out exactly what is going wrong in that method, simply that something *is* going wrong. Any ideas? It's such a simple example and yet it isn't working. My guess is I might be missing something in the soft body setup, since trying to emulate an example from the bullet softdemo wasn't too straightforward.
User avatar
dphil
Posts: 237
Joined: Tue Jun 29, 2010 10:27 pm

Re: Soft body update bounds failing

Post by dphil »

Hm, if I simplify the shape from a cube to a square:

Code: Select all

const btVector3	c[]={	btVector3(-1,-1,-1),
		btVector3(+1,-1,-1),
		btVector3(-1,+1,-1),
		btVector3(+1,+1,-1)};
the simulations runs, but the x values of each of the 4 vertices have taken on wildly large values (all of the shooting from +/-1 to 7.68079x10^15 in one simulation step. The y and z values of the vertices maintain reasonable values similar to their original state (oscillating mildly). The mystery deepens...
User avatar
dphil
Posts: 237
Joined: Tue Jun 29, 2010 10:27 pm

Re: Soft body update bounds failing

Post by dphil »

Seems the above oddities are likely due to loss of reference to the softBodyWorldInfo after it goes out of scope. Replacing my custom-made softBodyWorldInfo with dynamicsWorld->getWorldInfo() works fine.