Hello!
I just downloaded PhysX3.3 and for some reason my main physics object becomes null as soon as initialization code is finished.
Definition:
namespace g {
// PhysX
static PxPhysics* pPhysXSDK = NULL;
PxFoundation* pPhysXFoundation;
PxCooking* pPhysXCooking;
PxScene* pPhysXScene;
PxMaterial* pPxMaterial;
};
Initialization:
bool InitializePhysX()
{
static PxDefaultErrorCallback gDefaultErrorCallback;
static PxDefaultAllocator gDefaultAllocatorCallback;
static PxSimulationFilterShader gDefaultSFS = PxDefaultSimulationFilterShader;
g::pPhysXFoundation = PxCreateFoundation(PX_PHYSICS_VERSION, gDefaultAllocatorCallback, gDefaultErrorCallback);
if(!g::pPhysXFoundation)
{
MessageBox(0, "PxCreateFoundation() failed", "Error", MB_ICONERROR);
return false;
}
g::pPhysXSDK = PxCreatePhysics(PX_PHYSICS_VERSION, *g::pPhysXFoundation, PxTolerancesScale());
if(!g::pPhysXSDK)
{
MessageBox(0, "PxCreatePhysics() failed", "Error", MB_ICONERROR);
return false;
}
if(!PxInitExtensions(*g::pPhysXSDK))
{
MessageBox(0, "PxInitExtensions() failed", "Error", MB_ICONERROR);
return false;
}
PxSceneDesc psd(g::pPhysXSDK->getTolerancesScale());
psd.gravity = PxVec3(0.0f, -9.81f, 0.0f);
if(!psd.cpuDispatcher)
{
PxDefaultCpuDispatcher* cpuDispatcher = PxDefaultCpuDispatcherCreate(1);
if(!cpuDispatcher)
{
MessageBox(0, "PxDefaultCpuDispatcherCreate() failed", "Error", MB_ICONERROR);
return false;
}
psd.cpuDispatcher = cpuDispatcher;
}
if(!psd.filterShader)
{
psd.filterShader = gDefaultSFS;
}
g::pPhysXScene = g::pPhysXSDK->createScene(psd);
if(!g::pPhysXScene)
{
MessageBox(0, "PhysXSDK->createScene() failed", "Error", MB_ICONERROR);
return false;
}
g::pPxMaterial = g::pPhysXSDK->createMaterial(0.5, 0.5, 0.5);
g::pPhysXCooking = PxCreateCooking(PX_PHYSICS_VERSION, *g::pPhysXFoundation,
PxCookingParams(g::pPhysXSDK->getTolerancesScale()));
if(!g::pPhysXCooking)
{
MessageBox(0, "PxCreateCooking() failed", "Error", MB_ICONERROR);
return false;
}
return true;
}
Initialization returns true, but as soon as I try to do anything that involves calling the main PxPhysics object (g::pPhysXSDK) - like: creating material, the application crashes with unhandled exception error because g::pPhysXSDK is 0.
So I can use g::pPhysXSDK only inside InitializePhysX(). Meaning I can’t do anything at runtime… I don’t think it’s supposed to be this way.