Triggers + onTrigger() --> crash

I’m using Physx 3.2.3, trying to add a trigger to the scene, and catch trigger events with onTrigger()
The program crashes at scene->fetchResults(true);

here’s a brief code :
creating the scene :

class phx_events : public PxSimulationEventCallback
    void onConstraintBreak(PxConstraintInfo* constraints, PxU32 count)    {}
    void onWake(PxActor** actors, PxU32 count)    {}
    void onSleep(PxActor** actors, PxU32 count)   {}
    void onContact(const PxContactPairHeader& pair_header, const PxContactPair* pairs, 
        PxU32 pair_cnt)   {}
    void onTrigger(PxTriggerPair* pairs, PxU32 count)
PxSceneDesc sdesc(g_phxdev.sdk->getTolerancesScale());
    sdesc.gravity = PxVec3(0, -9.81f, 0);
    sdesc.flags = PxSceneFlag::eENABLE_ACTIVETRANSFORMS;
    sdesc.cpuDispatcher = PxDefaultCpuDispatcherCreate(1);
    sdesc.filterShader = PxDefaultSimulationFilterShader;
    sdesc.simulationEventCallback = new phx_events();
    PxScene* scene = g_phxdev.sdk->createScene(sdesc);

and creating trigger …

PxRigidDynamic* rbody = sdk->createRigidDynamic(PxTransform::createIdentity());
    rbody->setActorFlag(PxActorFlag::eDISABLE_GRAVITY, true);
    PxMaterial* mtl = sdk->createMaterial(0.5f, 0.5f, 0.1f);
    PxShape* shape = rbody->createShape(PxBoxGeometry(1.0f, 1.0f, 1.0f), *mtl);
    shape->setFlag(PxShapeFlag::eSIMULATION_SHAPE, false);
    shape->setFlag(PxShapeFlag::eTRIGGER_SHAPE, true);

when there is no trigger object (only normal rigid bodies), simulation runs without problems, but when I add the trigger (not in the middle of sim of course), it crashes on fetchResults() function from PhysX3_x86.dll. There is no entry to onTrigger function. Also when I set the simulationEventCallback to NULL, the crash doesn’t happen. So I guess it happens when fetchResults is trying to invoke callback functions or something.

Could any one give me a hint, or figure out where is the problem ?


its a little bit strange - you use a “non implemented” PxSimulationEventCallback.
Do you use the PxSimulationFilterCallback? If you are using it, show us the code inside.
I´m using my own PxSimulationFilterShader - everything works, in each PhysX 3.x version.
I didnt use the scene.filterCallback.

Its probably your timestepping - how do you do update your PhysX? (Its easier when you show us the code)
I guess your PhysX init code is only a code snippet - because some functions are missing.

mFoundation = PxCreateFoundation(PX_PHYSICS_VERSION,*mAllocatorCallback,*mErrorCallback); 
mProfileZoneManager = &PxProfileZoneManager::createProfileZoneManager(mFoundation);
mSDK = PxCreatePhysics(PxVersion, *mFoundation,scale,true, mProfileZoneManager );

… but you said it works when you dont use the trigger flags.
You didnt delete any shape inside your app while the simulation is running, dont you?

When it crashs, what is the reason? A nullpointer - an invalid pointer with specail bit pattern?
Just debug your code and see what happens when you add your trigger actor to the scene.

-> I see that you use the RELEASE libs.

You should use the DEBUG lib for debugging your application and get error / warning messages
when you do something wrong in PhysX. (PhysX will print a warning on the console as default)

RELEASE libs are only usefull when your application is completly - and you are going to release it.
(Or test it with these libs :) )

CHECKED libs are usefull for the usually developement - you dont get as much warnings when you use them.

DEBUG libs have most warning / error messages and you should use it to debug your code.

But I preffer the DEBUG libs for development :)

So you have to change to the DEBUG or CHECKED libs, and copy the DEBUG and the CHECKED dlls
inside your bin folder in case you choose DEBUG or the CHECKED dlls when you choose the CHECKED libs.
( And of course, you have to link against the desired one )

Another question: Why dont you use PhysX 3.2.4?

thanks for the tips ScreenOfDeath
actually it was my mistake, (overrided new) I was messing up with the code and forgot to call constructor of the PxSimulationEventCallback.

sorry and thanks

Hello, from 6 years later.

I deleted a shape with detachShape(), and the actor with removeActor and release, can’t I do that? How should I remove a shape at a given time then?

(I segfault in onTrigger when i try to access a method from otherShape)

nevermind, I had to use

pairs[i]->flags & PxTriggerPairFlag::eREMOVED_SHAPE_TRIGGER
pairs[i]->flags & PxTriggerPairFlag::eREMOVED_SHAPE_OTHER

to check if a shape has been removed, before using it.

But I don’t understand what is the count parameter. There is only one pair, how can they have several trigger events?