Howdy! First post here and first time using PhysX in a “production” environment. I am using Ogre3D 1.9 as my graphics library, and to link the two together, I am using a slightly modified library called OgrePhysX (I updated it for PhysX 3.3).
I am trying to create physics in my app, but alas, I am running into an access violation. I have done quite a bit of debugging and traced the issue to the exact lines.
The function that creates physics:
void World::init()
{
if (!mPxPhysics)
{
/*mAllocator = new PxDefaultAllocator();
mErrorOutputStream = new LogOutputStream();
mPxPhysics = PxCreatePhysics(PX_PHYSICS_VERSION, *mAllocator, *mErrorOutputStream, PxTolerancesScale());
if (!mPxPhysics)
{
Ogre::LogManager::getSingleton().logMessage("[OgrePhysX] Error: SDK initialisation failed.");
return;
}
PxCookingParams params;
mCookingInterface = PxCreateCooking(PX_PHYSICS_VERSION, &mPxPhysics->getFoundation(), params);
if (!mCookingInterface)
{
Ogre::LogManager::getSingleton().logMessage("[OgrePhysX] Error: Cooking initialisation failed.");
return;
}
if (!PxInitExtensions(*mPxPhysics))
{
Ogre::LogManager::getSingleton().logMessage("[OgrePhysX] Error: Extension initialisation failed.");
return;
}*/
static OgreErrorCallback* gErrorCallback = NULL;
static PxDefaultAllocator* gDefaultAllocatorCallback = NULL;
gErrorCallback = new OgreErrorCallback();
gDefaultAllocatorCallback = new PxDefaultAllocator();
PxFoundation* mFoundation = PxCreateFoundation(PX_PHYSICS_VERSION, *gDefaultAllocatorCallback, *gErrorCallback);
if (!mFoundation)
{
Ogre::LogManager::getSingleton().logMessage("[OgrePhysX] Error: PxCreateFoundation failed.");
return;
}
bool recordMemoryAllocations = true;
/*PxProfileZoneManager mProfileZoneManager = &PxProfileZoneManager::createProfileZoneManager(mFoundation);
if (!mProfileZoneManager)
{
Ogre::LogManager::getSingleton().logMessage("[OgrePhysX] Error: SDK initialisation failed.");
return;
}*/
PxProfileZoneManager* gProfileZoneManager;
gProfileZoneManager = &physx::PxProfileZoneManager::createProfileZoneManager(mFoundation);
mPxPhysics = PxCreatePhysics(PX_PHYSICS_VERSION, *mFoundation, PxTolerancesScale(), recordMemoryAllocations, gProfileZoneManager /*&mProfileZoneManager*/ );
if (!mPxPhysics)
{
Ogre::LogManager::getSingleton().logMessage("[OgrePhysX] Error: SDK initialisation failed.");
return;
}
//PxCookingParams *params;
mCookingInterface = PxCreateCooking(PX_PHYSICS_VERSION, mPxPhysics->getFoundation(), PxCookingParams(PxTolerancesScale()));
if (!mCookingInterface)
{
Ogre::LogManager::getSingleton().logMessage("[OgrePhysX] Error: Cooking initialisation failed.");
return;
}
if (!PxInitExtensions(*mPxPhysics))
{
Ogre::LogManager::getSingleton().logMessage("[OgrePhysX] Error: Extension initialisation failed.");
return;
}
//if (mPxPhysics->getPvdConnectionManager())
// PxExtensionVisualDebugger::connect(mPxPhysics->getPvdConnectionManager(), "localhost", 5425, 500, true);
//create default material
mDefaultMaterial = mPxPhysics->createMaterial(1.0f, 1.0f, 0.1f);
Ogre::LogManager::getSingleton().logMessage("[OgrePhysX] SDK created.");
}
}
A closer look at the line that is causing the issue:
mPxPhysics = PxCreatePhysics(PX_PHYSICS_VERSION, *mFoundation, PxTolerancesScale(), recordMemoryAllocations, gProfileZoneManager /*&mProfileZoneManager*/ );
The issue itself (error):
Unhandled exception at 0x069865CF (PhysX3Common_x86.dll) in Universe.exe: 0xC0000005: Access violation reading location 0x0000002C.
I added a breakpoint and none of the parameters appear to be null, also, some have been used above the issued line.
If I break the code at the error, I am redirected to the following:
PX_FORCE_INLINE void* platformAlignedAlloc(size_t size)
{
return _aligned_malloc(size, 16);
}
Regardless of my futile debugging and research, I have come up with nothing. If anybody can help me, it would be greatly appreciated.
Cheers,
Jacob