PhysX Character Controller tutorial - Crash

gmz1982

07-03-2009 09:14:51

Hi!

I have been trying to work with Character Controllers starting with the given PhysX tutorials. I created a capsule shaped controller and a box actor. I can push the box on the ground.
After that I tried to work with callbacks but the app crashes when the capsule and the box shapes are colliding.


enum GameGroup
{
GROUP_NON_COLLIDABLE,
GROUP_COLLIDABLE_NON_PUSHABLE,
GROUP_COLLIDABLE_PUSHABLE,
};

#define COLLIDABLE_MASK (1<<GROUP_COLLIDABLE_NON_PUSHABLE) | (1<<GROUP_COLLIDABLE_PUSHABLE)

NxControllerManager* gManager;
NxController *cm_controller;
NxController *charcont;



void SetActorCollisionGroup(NxActor *actor, NxCollisionGroup group)
{
NxU32 nbShapes = actor->getNbShapes();
NxShape*const* shapes = actor->getShapes();

while (nbShapes--)
{
shapes[nbShapes]->setGroup(group);
}
}



NxController* PX_createCharacterController()
{
NxOgre::UserAllocator gMyAllocator;
gManager = NxCreateControllerManager(&gMyAllocator);

NxCapsuleControllerDesc desc;
desc.setToDefault();
desc.radius = 25;
desc.height = 60;
desc.upDirection = NX_Y;
desc.slopeLimit = 0;
desc.skinWidth = 0.01f;
desc.stepOffset = 5.0;
desc.position.x = 0;
desc.position.y = 30;
desc.position.z = 0;
desc.callback = NULL;
//desc.callback = &gControllerHitReport;

cm_controller = gManager->createController(PXScene->getNxScene(), desc);
cm_controller->setCollision( true );

return cm_controller;
};



mActor = PXScene->createActor("TestWallActor", new NxOgre::Cube(100.0f), Vector3(100, 110, 100), "mass: 10.0" );
SetActorCollisionGroup( mActor->getNxActor(), GROUP_COLLIDABLE_NON_PUSHABLE );

charcont = PX_createCharacterController();


As you can see, callbacks are commented out right now, with or without it the code crashes if I use "SetActorCollisionGroup( mActor->getNxActor(), GROUP_COLLIDABLE_NON_PUSHABLE )"
or I use setGroup on all the shapes manually.

I use NxOgre 1.0 '21 and I move the controller with the code below:

NxU32 collisionFlags;
NxF32 sharpness = 0.5f;

charcont->move( NxVec3(-speed,0,0), COLLIDABLE_MASK, 0.000001f, collisionFlags, sharpness);

Any response would be helpful!

Thanks in advance!

nasirus1983

12-03-2009 13:51:04

Hi,

Replace NxOgre with PhysX SDK and many problem will disappear. It's better to spend some time and write some classes to integrate ogre with physx. Then you will be know, how it's working and what to change and you can use new tutorials form PhysX 2.8.1 which are great. NxOgre is good for creating box'es, cube's and other simple stuff.
Most simple thing to integrate PhysX with Ogre is to use setName for the actor or userdata. If you do this, then you can without any problems use all samples stuff directly from PhysX.

nargil

12-03-2009 14:15:19

try:

while (--nbShapes)
{
...
}

gmz1982

12-03-2009 19:11:06

Still crashes :(

betajaen

12-03-2009 19:14:12

Can you post a copy of the stack trace of the error? A screenshot or two will do.

gmz1982

12-03-2009 19:40:44

NxCharacter.dll!00376223()
[Frames below may be incorrect and/or missing, no symbols loaded for NxCharacter.dll]
PhysXCore.dll!065c62f3()
NxCharacter.dll!00377f4e()
PhysXCore.dll!065b66aa()
NxCharacter.dll!00378003()
NxCharacter.dll!00377ef2()
NxCharacter.dll!00374a01()
NxCharacter.dll!00375222()
NxCharacter.dll!003759ba()
NxCharacter.dll!00375773()
NxCharacter.dll!00375769()
ntdll.dll!7c919aeb()
ntdll.dll!7c919ba0()
NxCharacter.dll!00375758()
kernel32.dll!7c80ac78()
PhysXLoader.dll!003a14af()
NxCharacter.dll!00375741()
OgreMain.dll!10150cd3()
NxCharacter.dll!00375d11()
game.exe!0040a1b1()
> NxOgre.dll!NxOgre::Scene::simulate(float time=0.0020000001) Line 1371 + 0x24 bytes C++
NxOgre.dll!NxOgre::World::simulate(float time=1.745e-039#DEN) Line 160 + 0xf bytes C++
NxOgre.dll!NxOgre::PhysXDriver::simulate(float time=1.744e-039#DEN) Line 580 C++
OgreMain.dll!10143b9f()
OgreMain.dll!10146212()
game.exe!0040a653()
game.exe!0040a6ad()
game.exe!0040ea3c()
kernel32.dll!7c816d4f()
kernel32.dll!7c8399f3()

nargil

12-03-2009 21:24:09

Very nice little worms there. Haven't seen assembler since ~7 years (when I were around ~15 I typed out 15 pages of assembler from a book, and got my first pong ! I had no clue what I'm doing, though. Some of my friends probably got laid that evenings xD .But it was nothing compared to getting a nice,1 of 255 (or was it less hmmm), colour of my square pong-ball xD .Even if someone knows assembler very well: Imagine what small amount of code this is you're showing to us.). Use the fucking debug mode. xD That looks like release to me.

betajaen

12-03-2009 22:15:45

I agree with nargil; Use the fucking debug mode. It'll trace better and we won't have to get our 7 year old assembly manuals. It's also not NxCharacter.dll causing the problem (it's causing the crash), but something of yours is causing the problem.

nasirus1983

13-03-2009 09:55:39

Show code for your hit report controller.

gmz1982

14-03-2009 05:46:55

However, callback was commented out,

desc.callback = NULL;
//desc.callback = &gControllerHitReport;


here it is:

class ControllerHitReport : public NxUserControllerHitReport
{
public:
virtual NxControllerAction onShapeHit(const NxControllerShapeHit& hit)
{
if(1 && hit.shape)
{
}

return NX_ACTION_NONE;
};

virtual NxControllerAction onControllerHit(const NxControllersHit& hit)
{
return NX_ACTION_NONE;
};

} gControllerHitReport;


If it helps somebody, instead of:

NxController* PX_createCharacterController()
{
NxOgre::UserAllocator gMyAllocator;
gManager = NxCreateControllerManager(&gMyAllocator);


I used:

NxController* PX_createCharacterController()
{
//NxOgre::UserAllocator* gMyAllocator = new NxOgre::UserAllocator("somenamealpha");//for debug
NxOgre::UserAllocator* gMyAllocator = new NxOgre::UserAllocator();//for release
gManager = NxCreateControllerManager(gMyAllocator);


and it works..

nargil

14-03-2009 07:43:33

I usemManager = NxCreateControllerManager(GameEngine::getSingletonPtr()->getWorld()->getPhysXDriver()->getUserAllocator());
Are there any pros or cons of using this or an own allocator?