Crash with new midphase & serialization

Hi.

I’m trying to switch to using the new triangle mesh midphase, but I’m having trouble using it with a few specific meshes & serialization. Here’s the simplest example I’ve come up with:

// cook the mesh	
physx::PxVec3 pVertices[ 4 ];
pVertices[ 0 ] = physx::PxVec3( 8.0f, 0.0f, -8.0f );
pVertices[ 1 ] = physx::PxVec3( 8.0f, 0.0f, 8.0f );
pVertices[ 2 ] = physx::PxVec3( -8.0f, 0.0f, -8.0f );
pVertices[ 3 ] = physx::PxVec3( -8.0f, 0.0f, 8.0f );

physx::PxU32 pIndices[ 6 ] = { 2, 1, 0, 1, 2, 3 };

physx::PxTriangleMeshDesc meshDesc;
meshDesc.points.count = 4;
meshDesc.points.stride = sizeof( physx::PxVec3 );
meshDesc.points.data = pVertices;

meshDesc.triangles.count = 2;
meshDesc.triangles.stride = sizeof( physx::PxU32 ) * 3;
meshDesc.triangles.data = pIndices;
	
physx::PxDefaultMemoryOutputStream buf;

physx::PxTriangleMeshCookingResult::Enum result;
bool bSuccess = g_pPhysX->getCooking()->cookTriangleMesh( meshDesc, buf, &result );

// create the shape
physx::PxDefaultMemoryInputData input( buf.getData(), buf.getSize() );
physx::PxTriangleMesh* triangleMesh = PxGetPhysics().createTriangleMesh( input );

physx::PxTriangleMeshGeometry geometry( triangleMesh );
auto pShape = PxGetPhysics().createShape( geometry, *m_pPhysicsAPI->getDefaultMaterial(), true );

// create the actor
physx::PxRigidStatic* pRigidStatic = m_pPhysicsAPI->getPhysics()->createRigidStatic( physx::PxTransform( physx::PxVec3( 0.0f, 5.0f, 0.0f ) ) );
pRigidStatic->attachShape( *pShape );
pShape->release();

// serialize the collection
auto registry = physx::PxSerialization::createSerializationRegistry( PxGetPhysics() );

#if 1
auto collection = PxCreateCollection();
collection->add( *pRigidStatic );

physx::PxDefaultMemoryOutputStream outSerializationStream;
physx::PxSerialization::complete( *collection, *registry );

physx::PxSerialization::serializeCollectionToBinary( outSerializationStream, *collection, *registry );

static __declspec( align( 128 ) ) char pAlignedBuffer[ 1024 * 1024 ];
std::memcpy( pAlignedBuffer, outSerializationStream.getData(), outSerializationStream.getSize() );

physx::PxCollection* pCollection = physx::PxSerialization::createCollectionFromBinary( pAlignedBuffer, *registry );

physx::PxRigidActor* pRigidActor = pCollection->getObject( 3 ).is< physx::PxRigidActor >(); // very hacky here to assume 3 is the index
if( pRigidActor )
{
	m_pScene->addActor( *pRigidActor );
}
#else
m_pScene->addActor( *pRigidStatic );
#endif

If I add an actor in the scene using that code and the new midphase enabled in midphaseDesc, I get a crash when trying to use the debug lines functionality, or when doing any queries related to that mesh, etc. If I use the old midphase, or if I change the #if 1 line to #if 0 to skip the serialization, everything works fine. Everything also works if I use less simple mesh data.

The crash I get is in:

>	PhysX3CommonDEBUG_x64.dll!physx::shdfnd::aos::V4LoadA(const float * const f) Line 408	C++
 	PhysX3CommonDEBUG_x64.dll!BV4_ProcessNodeNoOrder_Swizzled<`anonymous namespace'::LeafFunction_BoxOverlapAll,1,OBBParamsAll>(unsigned int * Stack, unsigned int & Nb, const physx::Gu::BVDataSwizzled * node, OBBParamsAll * params) Line 37	C++
 	PhysX3CommonDEBUG_x64.dll!BV4_ProcessStreamSwizzledNoOrder<`anonymous namespace'::LeafFunction_BoxOverlapAll,OBBParamsAll>(const physx::Gu::BVDataPacked * node, unsigned int initData, OBBParamsAll * params) Line 56	C++

Looks like it runs out of GU_BV4_STACK_SIZE, nb is 264. The stack array looks weird:

0x0000005049ed90c0 {65536, 0, 0, 65536, 0, 0, 65536, 0, 0, 65536, 0, 0, 65536, 0, 0, 65536, 0, 0, 65536, …}

Thanks for reporting this. We have a fix which should be available through the next patch on GitHub.