Access violation while creating PhysX

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

Right, solved it by changing the following:

mPxPhysics = PxCreatePhysics(PX_PHYSICS_VERSION, *mFoundation, PxTolerancesScale(), recordMemoryAllocations,  gProfileZoneManager /*&mProfileZoneManager*/ );

to:

mPxPhysics = PxCreatePhysics(PX_PHYSICS_VERSION, *mFoundation, PxTolerancesScale());//, recordMemoryAllocations, NULL /*gProfileZoneManager /*&mProfileZoneManager*/ );

I then ran into the same issue with cooking, so I did this:

Changed

//PxCookingParams *params;
mCookingInterface = PxCreateCooking(PX_PHYSICS_VERSION, mPxPhysics->getFoundation(), PxCookingParams(PxTolerancesScale()));

to

PxTolerancesScale toleranceScale;
toleranceScale.mass = 1000;
toleranceScale.speed = 9;
bool value = toleranceScale.isValid();
if(value != true){
    Ogre::LogManager::getSingleton().logMessage("[OgrePhysX] Tolerance Value is false.");
    return;
}
mCookingInterface = PxCreateCooking(PX_PHYSICS_VERSION, *mFoundation, toleranceScale);

Now I am having an issue with creating a rigid dynamic actor.

..\..\PhysXCooking\src\convex\ConvexHullBuilder.cpp (1486) : unknown error : ConvexHullBuilder: convex hull has more than 255 polygons!

..\..\PhysXCooking\src\convex\ConvexMeshBuilder.cpp (266) : unknown error : Gu::ConvexMesh::loadConvexHull: convex hull init failed! Try to use the PxConvexFlag::eINFLATE_CONVEX flag. (see PxToolkit::createConvexMeshSafe)

..\..\PhysX\src\NpFactory.cpp (666) : invalid parameter : Supplied PxGeometry is not valid. Shape creation method returns NULL.

First-chance exception at 0x00BB215A (PhysX3CHECKED_x86.dll) in Universe.exe: 0xC0000005: Access violation reading location 0x00000004.
Unhandled exception at 0x00BB215A (PhysX3CHECKED_x86.dll) in Universe.exe: 0xC0000005: Access violation reading location 0x00000004.

I am going to try the flag it suggested and I will report back with more details!