PhysXCallback::onContactNotify problem

nishnu

15-09-2009 22:05:11

Hi all, this is my first post :-)

I have a problem with:
PhysXCallback::onContactNotify, it's from the latest NxOgre version from git repo.
I'll paste the code:

void PhysXCallback::onContactNotify(NxContactPair &pair, NxU32 events)
{

if (pair.isDeletedActor[0] || pair.isDeletedActor[1])
return;

if (!pair.actors[0]->userData && !pair.actors[1]->userData)
return;

RigidBody* rbody_a = pointer_representive_cast<RigidBody>(pair.actors[0]->userData);
RigidBody* rbody_b = pointer_representive_cast<RigidBody>(pair.actors[1]->userData);

ContactPair contact_pair;
contact_pair.mFirst = rbody_a;
contact_pair.mSecond = rbody_b;
contact_pair.mSumFrictionForce = pair.sumFrictionForce;
contact_pair.mSumNormalForce = pair.sumNormalForce;

if (rbody_a->getContactCallback() != 0)
rbody_a->getContactCallback()->onContact(contact_pair);

if (rbody_b->getContactCallback() != 0)
rbody_b->getContactCallback()->onContact(contact_pair);

}


the problem is that when I create an actor directly in PhysX (to be specific I try to use a character controller) and set userData to null I get a null pointer exception in the line that tries to call getContactCallback(). When you look at it - this method does not deal with the case when one of rigidBody's userData is null.
Is it ok to create actors bypassing NxOgre ?
Or am I missing something else ?
Or did I find a bug ? :-)

Sory for my english ;-)

betajaen

15-09-2009 22:28:01

It isn't recommended that you create PhysX NxActors directly when NxOgre is running.

However; Try changing this:

if (!pair.actors[0]->userData && !pair.actors[1]->userData)
return;


to this;

if (pair.actors[0]->userData == 0 || pair.actors[1]->userData == 0)
return;


You won't be able to put any userData in your NxActor, there is no way around it. The other solution is to sub-class RigidBody and in effect create your own Actor class, like how Actor is. You'll have the comforts of NxOgre looking after it, and you won't get strange crashes like that.

But before you do that; If you like, post what PhysX code you have, and I'll see if I can translate it in NxOgre for you.

nishnu

15-09-2009 23:10:42

Thanks for your reply.

I try to create a character controller. I'm following PhysX SDK "Training Programs".
The code is more-less like below.
Somewhere in my GameEngine:

mControllerManager = NxCreateControllerManager(&mWorld->getPhysXSDK()->getFoundationSDK().getAllocator());

somewhere in the game loop:

mControllerManager->updateControllers();

In my Player class:

NxCapsuleControllerDesc mCtrlDescr;
mCtrlDescr.radius = 1;
mCtrlDescr.position = NxExtendedVec3(4, 5, 4);
mCtrlDescr.height = 2;
mCtrlDescr.callback = NULL;
mCtrlDescr.climbingMode = CLIMB_EASY;
mController = GameEngine::getSingletonPtr()->getControllerManager()->createController(mScene->getScene(),mCtrlDescr);
mController->getActor()->userData = NULL;

then there's the update method:

Vec3 disp(mFPPCamera->getOrientation()*mTranslate);
disp.y = 0;
disp.normalise();
disp *= deltaTime * mParams.mMaxSpeed;
NxU32 collisionFlags;
mController->move(disp.as<NxVec3>(), 0xffffffff, 0.001, collisionFlags);
mFPPCamera->setPosition(mController->getPosition().x,mController->getPosition().y, mController->getPosition().z);

Nothing fancy, just doing my first steps with Ogre, some physics and the whole concept :-)

It's ok untill my character controller collides with a NxOgre-created OGRE3DBody. Collisions with static geometry are fine.
I tried doing this through PhysX, because I read that some people had problems with KinematicController (here for instance), but maybe I'll give it a try :-)