Access violation dealing with btKinematicCharacterController

Post Reply
E333
Posts: 3
Joined: Thu Dec 09, 2010 7:32 pm

Access violation dealing with btKinematicCharacterController

Post by E333 »

Hi,

I'm relatively new to bullet (3 or 4 weeks, I think :)), and I've got some Problems while using btKinematicCharacterController.

With this Code:

Code: Select all

auto pShape = new btCapsuleShape(10,10);
m_pGhostObject = new btPairCachingGhostObject();
m_pGhostObject->setWorldTransform(btTransform(btMatrix3x3::getIdentity(), btVector3(0,30,0)));
m_pGhostObject->setCollisionShape(pShape);
m_pGhostObject->setCollisionFlags(m_pGhostObject->getCollisionFlags()|btCollisionObject::CF_CHARACTER_OBJECT);

m_pCharacterController = new btKinematicCharacterController(m_pGhostObject, pShape, 0.1, 1);

m_pDynamicsWorld->addCollisionObject(m_pGhostObject, btBroadphaseProxy::CharacterFilter, btBroadphaseProxy::StaticFilter|btBroadphaseProxy::DefaultFilter);
m_pDynamicsWorld->addAction (m_pCharacterController);
This Code produces an Access Violation during runtime. This happens at

Code: Select all

// btKinematicCharacterController.cpp line 87
hitNormalWorld = m_hitCollisionObject->getWorldTransform().getBasis()*convexResult.m_hitNormalLocal;
because m_hitCollisionObject is a nullpointer. (this code is a member of the btKinematicClosestNotMeConvexResultCallback::addResult method ;) )

What's going wrong, and what can I do to get this Working ?

Sincerely,
E333
E333
Posts: 3
Joined: Thu Dec 09, 2010 7:32 pm

Re: Access violation dealing with btKinematicCharacterContro

Post by E333 »

Noone an idea?
DragonGeo2
Posts: 16
Joined: Sat Dec 18, 2010 1:30 am

Re: Access violation dealing with btKinematicCharacterContro

Post by DragonGeo2 »

Well I believe that I am having a similar problem. I created a collision dispatcher and a discrete dynamics world object with the parameters passed to it exactly as the demos have them. Next, I created a pair caching ghost object and set its collision shape to a new instance of a capsule shape. Finally, I created a kinematic character controller object and initialized it to that ghost object. Then I added the character controller as an action into the dynamics world. All of this code I took directly from the samples.

When I added debug drawing, that was fine. It gave me a capsule that just fell forever. It worked great!

But then, I wanted to add a world for my player to mess around in. So I created a new heightfield terrain shape and initialized it with similar parameters as the heightfield demo showed. The debug drawer ran really slowly (it's a 65x65 heightmap) but that's alright because the debug drawer drew my terrain correctly (it even showed the terrain normals right!). My problem occurred when I ran my simulation and let the player object fall from up high onto the terrain. I get a null pointer dereference on the member variable m_hitCollisionObject (it is NULL) as called from btKinematicCharacterController::addSingleResult. Here's a picture of my call stack (NewPhysicsUpdateStep being my main physics loop):
http://dragongeo2.net/temp/CallStack.png
DragonGeo2
Posts: 16
Joined: Sat Dec 18, 2010 1:30 am

Re: Access violation dealing with btKinematicCharacterContro

Post by DragonGeo2 »

I think the crash is fixed by changing line 87 of btKinematicCharacterController.cpp from:
hitNormalWorld = m_hitCollisionObject->getWorldTransform().getBasis()*convexResult.m_hitNormalLocal;
to:
hitNormalWorld = convexResult.m_hitCollisionObject->getWorldTransform().getBasis()*convexResult.m_hitNormalLocal;

But I'm not sure if that modifies the correctness of Bullet's character controller. However, it does result in my program no longer crashing.
E333
Posts: 3
Joined: Thu Dec 09, 2010 7:32 pm

Re: Access violation dealing with btKinematicCharacterContro

Post by E333 »

Finally all my Problems solved themselves by using btBvhTrimeshShape for Terrain ;)
ebenezer
Posts: 1
Joined: Tue Apr 05, 2011 4:51 pm

Re: Access violation dealing with btKinematicCharacterContro

Post by ebenezer »

I also see this crash. DragonGeo2's change seems to fix it, but I wonder if it's the correct way to do so or if I've caused bigger problems.
User avatar
Erwin Coumans
Site Admin
Posts: 4221
Joined: Sun Jun 26, 2005 6:43 pm
Location: California, USA
Contact:

Re: Access violation dealing with btKinematicCharacterContro

Post by Erwin Coumans »

The fix by DragonGeo2 is OK, and has already been applied in latest trunk.

Thanks,
Erwin
Post Reply