btKinematicCharacterController vs btStaticPlaneShape bug?

firo
Posts: 4
Joined: Thu Sep 30, 2010 2:55 pm

btKinematicCharacterController vs btStaticPlaneShape bug?

Post by firo »

Hi,
Im using btKinematicCharacterController in some program, when controller colide with btStaticPlaneShape program fall in btKinematicClosestNotMeConvexResultCallback::addSingleResult(btCollisionWorld::LocalConvexResult&, bool) segmentation fault.

Here is modified function CharacterDemo::initPhysics() from Demos/CharacterDemo/CharacterDemo.cpp with problem

Code: Select all

void CharacterDemo::initPhysics()
{
	m_collisionConfiguration = new btDefaultCollisionConfiguration();
	m_dispatcher = new btCollisionDispatcher(m_collisionConfiguration);
	btVector3 worldMin(-1000,-1000,-1000);
	btVector3 worldMax(1000,1000,1000);
	btAxisSweep3* sweepBP = new btAxisSweep3(worldMin,worldMax);
	m_overlappingPairCache = sweepBP;

	m_constraintSolver = new btSequentialImpulseConstraintSolver();
	m_dynamicsWorld = new btDiscreteDynamicsWorld(m_dispatcher,m_overlappingPairCache,m_constraintSolver,m_collisionConfiguration);

#ifdef DYNAMIC_CHARACTER_CONTROLLER
	m_character = new DynamicCharacterController ();
#else

	btTransform startTransform;
	startTransform.setIdentity ();
	//startTransform.setOrigin (btVector3(0.0, 4.0, 0.0));
	startTransform.setOrigin (btVector3(10.210098,-1.6433364,16.453260));

	m_ghostObject = new btPairCachingGhostObject();
	m_ghostObject->setWorldTransform(startTransform);
	sweepBP->getOverlappingPairCache()->setInternalGhostPairCallback(new btGhostPairCallback());
	btScalar characterHeight=1.75;
	btScalar characterWidth =1.75;
	btConvexShape* capsule;
	//capsule = new btBoxShape(btVector3(characterWidth, characterHeight, characterWidth));
	capsule = new btCapsuleShape(characterWidth,characterHeight);
	m_ghostObject->setCollisionShape (capsule);
	m_ghostObject->setCollisionFlags (btCollisionObject::CF_CHARACTER_OBJECT);

	btScalar stepHeight = btScalar(0.35);
	m_character = new btKinematicCharacterController (m_ghostObject,capsule,stepHeight);

#endif

    btCollisionShape* groundShape;
    /** Box OK */
    //groundShape = new btBoxShape(btVector3(50,3,50));

    /** Trimesh OK*/
    //btTriangleMesh* trimesh = new btTriangleMesh();
    //trimesh->addTriangle(btVector3(-100, 0, -100), btVector3(100, 0, -100), btVector3(0, 0, 100));
    //groundShape = new btBvhTriangleMeshShape(trimesh, true);

    /** StaticPlane not OK */
    groundShape = new btStaticPlaneShape(btVector3(0, 1, 0), 1);    //fall

    btTransform t2;
    t2.setIdentity();
    t2.setOrigin(btVector3(0, -10, 0));
    m_collisionShapes.push_back(groundShape);
    localCreateRigidBody(0,  t2, groundShape);


	///only collide with static for now (no interaction with dynamic objects)
	m_dynamicsWorld->addCollisionObject(m_ghostObject,btBroadphaseProxy::CharacterFilter, btBroadphaseProxy::StaticFilter|btBroadphaseProxy::DefaultFilter);

	m_dynamicsWorld->addAction(m_character);

	///////////////

	clientResetScene();

	setCameraDistance(56.f);

}
I am run on Ubutnu 10.04 64bit, Bullet 2.77
Thanks
(sorry for my english)
SteveSegreto
Posts: 32
Joined: Sun Sep 12, 2010 10:25 am

Re: btKinematicCharacterController vs btStaticPlaneShape bug

Post by SteveSegreto »

I haven't got a clue what you are trying to ask. Are you asking about the character's capsule falling through the static plane thereby giving incorrect visual results? Or are you asking about receiving a segmentation fault *FAILURE* when attempting to construct a static plane rigid body?

If you are asking about a segmentation fault failure, please include the call stack for the failure.
firo
Posts: 4
Joined: Thu Sep 30, 2010 2:55 pm

Re: btKinematicCharacterController vs btStaticPlaneShape bug

Post by firo »

Program crash "Program received signal SIGSEGV, Segmentation fault." when character collide with static rigid body plane.

call stack:

Code: Select all

#0 0x44db28	btKinematicClosestNotMeConvexResultCallback::addSingleResult(btCollisionWorld::LocalConvexResult&, bool) () (??:??)
#2 0x4aa220	btTriangleConvexcastCallback::processTriangle(btVector3*, int, int) () (??:??)
#4 0x48cddb	btCollisionWorld::objectQuerySingle(btConvexShape const*, btTransform const&, btTransform const&, btCollisionObject*, btCollisionShape const*, btTransform const&, btCollisionWorld::ConvexResultCallback&, float) () (??:??)
#6 0x44c5b6	btKinematicCharacterController::stepDown(btCollisionWorld*, float) () (??:??)
#7 0x44d970	btKinematicCharacterController::playerStep(btCollisionWorld*, float) () (??:??)
#8 0x45efd2	btDiscreteDynamicsWorld::internalSingleStepSimulation(float) () (??:??)
#9 0x45cfd2	btDiscreteDynamicsWorld::stepSimulation(float, int, float) () (??:??)
#10 0x43393b	CharacterDemo::clientMoveAndDisplay() () (??:??)
#11 0x7ffff7bb6c4f	glutMainLoop() (/usr/lib/libglut.so.3:??)
#12 0x4465ca	glutmain(int, char**, int, int, char const*, DemoApplication*) () (??:??)
#13 0x7ffff6c12c4d	__libc_start_main() (/lib/libc.so.6:??)
#14 0x4306f9	_start() (??:??)
SteveSegreto
Posts: 32
Joined: Sun Sep 12, 2010 10:25 am

Re: btKinematicCharacterController vs btStaticPlaneShape bug

Post by SteveSegreto »

I'm still not sure about the crash from the callstack - do u have one with line numbers in it?

The plane equation is:

Ax + By + Cz + D = 0

So, it seems like if you are providing a plane normal of { 0, 1, 0 } then wouldn't the planeConstant (D) have to equal -1.0f to satisfy the equation above?

i.e.

groundShape = new btStaticPlaneShape(btVector3(0, 1, 0), -1);
SteveSegreto
Posts: 32
Joined: Sun Sep 12, 2010 10:25 am

Re: btKinematicCharacterController vs btStaticPlaneShape bug

Post by SteveSegreto »

By the way i was not able to repro your crash using the bullet 2.76 character demo. In the initPhysics function rather than creating rigid bodies from quake BSP file(s), I instead created one using the ground shape, which i first created as a btStaticPlaneShape, but I couldn't get the crash that you received.
SteveSegreto
Posts: 32
Joined: Sun Sep 12, 2010 10:25 am

Re: btKinematicCharacterController vs btStaticPlaneShape bug

Post by SteveSegreto »

OK I was able to repro on Bullet 2.77, its a problem with the btKinematicCharacterController's btKinematicClosestNotMeConvexResultCallback callback routine. Specifically, the m_hitCollisionObject is a NULL pointer, causing the segfault.

In btKinematicCharacterController.cpp in btKinematicClosestNotMeConvexResultCallback::addSingleResult, this line:

///need to transform normal into worldspace
hitNormalWorld = m_hitCollisionObject->getWorldTransform().getBasis()*convexResult.m_hitNormalLocal;


Should read like this instead:

///need to transform normal into worldspace
hitNormalWorld = convexResult.m_hitCollisionObject->getWorldTransform().getBasis()*convexResult.m_hitNormalLocal;

Then you need to recompile the BulletDynamics library.

That will stop the crash, but I suspect the larger error is why the m_hitCollisionObject of the callback routine is being left un-initialized?
firo
Posts: 4
Joined: Thu Sep 30, 2010 2:55 pm

Re: btKinematicCharacterController vs btStaticPlaneShape bug

Post by firo »

Thank you, it works fine.