PhysX NuGet package - PxPhysics initialization fails


I would like to include PhysX in my project as a NuGet package. When creating the NuGet package I need to set the projects runtime settings from MT/MTd to MD/MDd int order for it to be compatible with my projects. This all seems to work and the NuGet package is created, however, I have some trouble with the initialization of the PxPhysics object.

pxPhysics = PxCreatePhysics(PX_PHYSICS_VERSION, *pxFoundation, toleranceScale, recordMemoryAllocations);

When calling this function a nullptr is returned. Has anyone run into an issue similar to this? Does it have to do with the creation of the NuGet package?

Figured I might just have made a mistake in my initialization code so here it is:


    using namespace physx;

static PxFoundation* pxFoundation = nullptr;
static PxCooking* pxCooking = nullptr;
static PxPhysics* pxPhysics = nullptr;

void Initialize()
	PxDefaultErrorCallback gDefaultErrorCallback;
	PxDefaultAllocator gDefaultAllocatorCallback;

	auto tolerance = (PxReal)100.0;

	PxTolerancesScale toleranceScale;
	toleranceScale.length = tolerance;
	toleranceScale.mass = tolerance;
	toleranceScale.speed = tolerance;

	pxFoundation = PxCreateFoundation(PX_FOUNDATION_VERSION, gDefaultAllocatorCallback, gDefaultErrorCallback);

	bool recordMemoryAllocations = true;

	pxPhysics = PxCreatePhysics(PX_PHYSICS_VERSION, *pxFoundation, toleranceScale, recordMemoryAllocations);

	PxCookingParams cookingParams(toleranceScale);
	cookingParams.suppressTriangleMeshRemapTable = false;
	cookingParams.meshWeldTolerance = tolerance;
	cookingParams.meshPreprocessParams = PxMeshPreprocessingFlag::eDISABLE_CLEAN_MESH;

	pxCooking = PxCreateCooking(PX_PHYSICS_VERSION, *pxFoundation, cookingParams);


Side note: I also ran this same code by including PhysX as a library and then it worked fine.