PhysX 3.3 debug heap corruption Windows 10

I am getting heap corruption errors at various times on Windows 10 when creating PhysX objects. This usually occurs during initialisation when creating a material or a scene for the first time but does not always occur.

My initialisation code (in GPhysics()) is as follows:

foundation = PxCreateFoundation(PX_PHYSICS_VERSION, allocator, errorCallback);
PxTolerancesScale scale;
scale.length = 100; // Typical length of an object
scale.speed = 981; // Typical speed. Gravity is a reasonable choice
physics = PxCreatePhysics(PX_PHYSICS_VERSION, *foundation, scale, false);
defaultMaterial = physics->createMaterial(DefaultStaticFriction, DefaultDynamicFriction, DefaultRestitution);

When the crash occurs while creating a material the call stack is as follows:

ntdll.dll!00007ffec58b771e() 	
[Frames below may be incorrect and/or missing, no symbols loaded for ntdll.dll]	
ntdll.dll!00007ffec58bdf0a() 	
ntdll.dll!00007ffec5864f32() 	
ntdll.dll!00007ffec57ef530() 	
ntdll.dll!00007ffec57eb89a() 	
GameEngine.dll!heap_alloc_dbg_internal(const unsigned __int64 size, const int block_use, const char * const file_name, const int line_number)  Line 359 + 0x14 bytes	C++
GameEngine.dll!heap_alloc_dbg(const unsigned __int64 size, const int block_use, const char * const file_name, const int line_number)  Line 450 + 0x18 bytes	C++
GameEngine.dll!_malloc_dbg(const unsigned __int64 size, const int block_use, const char * const file_name, const int line_number)  Line 496	C++
GameEngine.dll!_aligned_offset_malloc_dbg(const unsigned __int64 size, unsigned __int64 alignment, const unsigned __int64 offset, const char * const file_name, const int line_number)  Line 1800 + 0x1f bytes	C++
GameEngine.dll!_aligned_malloc(const unsigned __int64 size, const unsigned __int64 alignment)  Line 498	C++
GameEngine.dll!GPhysics::Allocator::allocate(unsigned __int64 size, const char * __formal, const char * __formal, const char * __formal)  Line 33	C++
PhysX3CommonDEBUG_x64.dll!physx::shdfnd::Foundation::AlignCheckAllocator::allocate(unsigned __int64 size, const char * typeName, const char * filename, int line)  Line 237 + 0x2f bytes	C++
PhysX3CommonDEBUG_x64.dll!physx::shdfnd::NamedAllocator::allocate(unsigned __int64 size, const char * filename, int line)  Line 75 + 0x3b bytes	C++
 	PhysX3DEBUG_x64.dll!physx::shdfnd::PoolBase<physx::NpMaterial,physx::shdfnd::NamedAllocator>::allocateSlab()  Line 183 + 0x28 bytes	C++
 	PhysX3DEBUG_x64.dll!physx::shdfnd::PoolBase<physx::NpMaterial,physx::shdfnd::NamedAllocator>::allocate()  Line 65	C++
 	PhysX3DEBUG_x64.dll!physx::shdfnd::PoolBase<physx::NpMaterial,physx::shdfnd::NamedAllocator>::construct<physx::PxsMaterialData>(physx::PxsMaterialData & a)  Line 107 + 0xd bytes	C++
PhysX3DEBUG_x64.dll!physx::NpFactory::createMaterial(float staticFriction, float dynamicFriction, float restitution)  Line 765 + 0x18 bytes	C++
PhysX3DEBUG_x64.dll!physx::NpPhysics::createMaterial(float staticFriction, float dynamicFriction, float restitution)  Line 504 + 0x1f bytes	C++
GameEngine.dll!GPhysics::GPhysics()  Line 23 + 0x43 bytes	C++

The error message is as follows:

Critical error detected c0000374
Windows has triggered a breakpoint in [game exe]

This may be due to a corruption of the heap, which indicates a bug in [game exe] or any of the DLLs it has loaded.

This may also be due to the user pressing F12 while [game exe] has focus.

The output window may have more diagnostic information.

The program '[15284] [game exe]: Native' has exited with code -1 (0xffffffff).

I’m using the debug build but it seems like I haven’t configured my project correctly because the crash is happening in such a simple case and is in a very common code path. Are there any special compiler flags that need to be set? I have linked PhysX into a game engine dll which is linked to my main game EXE. Could the fact that it’s not linked directly into my main exe and memory allocations are being done in the game engine dll be a problem?

I think I found the problem. My PxCpuDispatcher class was a concrete object rather than a pointer created using PX_NEW. As soon as I made it a pointer the memory corruption stopped.