Error with "serializable->is<PxJoint>()" (No PxTypeInfo for PxJoint?)

Hello,

I’m iterating over a PxCollection (PhysX 3.2.1). For each

PxSerializable* obj = collection->getObject(i)

I can test if the object is an actor (whatever the concrete type) with

obj->is()

but I cannot test if the object is a joint (whatever the concrete type) with

obj->is()

because it gives a compile-time error:

I’ve had a look at PhysX headers for PxTypeInfo and PxJoint:

// ----------------------------------------
// PxTypeInfo.h

// ... things before the list ...

PX_DEFINE_TYPEINFO(PxSerializable,      PxConcreteType::eUNDEFINED);
PX_DEFINE_TYPEINFO(PxObservable,        PxConcreteType::eUNDEFINED);
/*snip*/
PX_DEFINE_TYPEINFO(PxActor,             PxConcreteType::eUNDEFINED);
PX_DEFINE_TYPEINFO(PxRigidActor,        PxConcreteType::eUNDEFINED);
PX_DEFINE_TYPEINFO(PxRigidBody,         PxConcreteType::eUNDEFINED);
PX_DEFINE_TYPEINFO(PxRigidDynamic,      PxConcreteType::eRIGID_DYNAMIC);
PX_DEFINE_TYPEINFO(PxRigidStatic,       PxConcreteType::eRIGID_STATIC);
/*snip*/
PX_DEFINE_TYPEINFO(PxConstraint,        PxConcreteType::eCONSTRAINT);
/*snip*/
PX_DEFINE_TYPEINFO(PxParticleSystem,    PxConcreteType::ePARTICLE_SYSTEM);

// ... things after the list ...

// ----------------------------------------
// PxJoint.h

// ... things before the list ...

/*
 *** NOTE: there's no entry for PxJoint in the list below! ***
 */
PX_DEFINE_TYPEINFO(PxFixedJoint,        PxConcreteType::eUSER_FIXED_JOINT);
PX_DEFINE_TYPEINFO(PxRevoluteJoint,     PxConcreteType::eUSER_REVOLUTE_JOINT);
PX_DEFINE_TYPEINFO(PxPrismaticJoint,    PxConcreteType::eUSER_PRISMATIC_JOINT);
PX_DEFINE_TYPEINFO(PxSphericalJoint,    PxConcreteType::eUSER_SPHERICAL_JOINT);
PX_DEFINE_TYPEINFO(PxDistanceJoint,     PxConcreteType::eUSER_DISTANCE_JOINT);
PX_DEFINE_TYPEINFO(PxD6Joint,           PxConcreteType::eUSER_D6_JOINT);

// ... things after the list ...

Thus the struct PxTypeInfo is never specialized for PxJoint. Why is that? Do I have to test instead with obj->is<PxConstraint>() then fetch the PxJoint with constraint->getExternalReference()?

Thank you.

Hi,

This looks like a bug. If you open PxJoint.h, it should be possible to add the following code to make it work:

PX_DEFINE_TYPEINFO(PxJoint, PxConcreteType::eUNDEFINED);

(just above the line “PX_DEFINE_TYPEINFO(PxFixedJoint…”)

A defect will get filed to look into this in future releases. Thanks for letting us know.

Thank you for acknowledging.

Just for the record, here’s another “workaround” (in alternative to completing the header or passing via PxConstraint):

PxU32 nbObjects = collection->getNbObjects();
	for (PxU32 i = 0; i < nbObjects; ++i) {
		PxSerializable* obj = collection->getObject(i);
		PxType concreteType = obj->getConcreteType();
		switch (concreteType) {
		case PxConcreteType::eUSER_SPHERICAL_JOINT:
		case PxConcreteType::eUSER_REVOLUTE_JOINT:
		case PxConcreteType::eUSER_PRISMATIC_JOINT:
		case PxConcreteType::eUSER_FIXED_JOINT:
		case PxConcreteType::eUSER_DISTANCE_JOINT:
		case PxConcreteType::eUSER_D6_JOINT:
			{
				PxJoint* joint = static_cast<PxJoint*>(obj);
				// ...
			}
			break;
		default:
			break;
		}
	}

(but the less generic of all.)