Crash in Engine: ..\..\GeomeUtils\src\mesh\GuTriangleMesh.cpp\invalid operation : Gu::triangleMesh:

Hi guys,

I have an annoying crash in my physx code which I’m struggling to fix. It only occurs in release mode so it’s tricky to fix. It occurs when I use createTriangleMesh to create a static mesh. The crash occurs when createShape is called but the following error appears in the console just before the crash happens:

Crash in Engine: …\GeomeUtils\src\mesh\GuTriangleMesh.cpp\invalid operation : Gu::triangleMesh::release: double deletion detected!

I’ve checked the mesh for obvious errors in the vertex and index buffer and it seems to be OK.

I’m using PhysX 3.3 and visual studio 2013. I seem to remember hearing about this error before but I can’t find any reference to it now.

Anyone know how to fix this?

regards,

Tony

This is my code for creating the triangle mesh. I tried with other meshes and I always get the same error in release. But in debug I don’t get the error and the resultant mesh works fine in the simulation.

void Room::attachedRigidBodyMesh(PxMaterial* g_PhysicsCaveMaterial)
{
	//need a placeholder box
	PxBoxGeometry box = PxBoxGeometry(1, 1, 1);
	PxTransform transform(*(PxMat44*)(&_transform[0])); //PhysX and GLM matricies are the same internally so we simply cast between them;
	_pXactor = PxCreateStatic(*caveEngine->m_PhysXComponent->g_Physics, transform, box, *g_PhysicsCaveMaterial);

	//set up the descriptors for PhysX.  We take the data straight from the data we use for rendering

	PxTriangleMeshDesc meshDesc;
	meshDesc.points.count = _roomMesh->getNumberVerts();
	meshDesc.points.stride = sizeof(Vertex);
	meshDesc.points.data = &(_roomMesh->getAoVertices()->position);  //we can do thi because GLM vector4 is the same for XYZ as PhysX vec3.

	meshDesc.triangles.count = _roomMesh->getNumberIndex() / 3;
	meshDesc.triangles.stride = 3 * sizeof(PxU32);
	meshDesc.triangles.data = _roomMesh->getAuiIndices();

	PxDefaultMemoryOutputStream* buf = new PxDefaultMemoryOutputStream();
	assert(caveEngine->m_PhysXComponent->g_PhysicsCooker->cookTriangleMesh(meshDesc, *buf));
	PxU8* contents = buf->getData();
	PxU32 size = buf->getSize();
	PxDefaultMemoryInputData input(contents, size);
	PxTriangleMesh* triangleMesh = caveEngine->m_PhysXComponent->g_Physics->createTriangleMesh(input);
	PxTransform pose = PxTransform(PxVec3(0.0f, 0, 0.0f));  //verticies are in world space so no transform

	//double deletion and crash occur on the next line
	_pXactor->createShape(PxTriangleMeshGeometry(triangleMesh), *g_PhysicsCaveMaterial, pose); 


//	//remove the placeholder box we started with
//	int numberShapes = _pXactor->getNbShapes();
//	PxShape** shapes = (PxShape**)_aligned_malloc(sizeof(PxShape*)*numberShapes, 16);
//	_pXactor->getShapes(shapes, numberShapes);
//	_pXactor->detachShape(**shapes);

	//Add it to the scene
//	caveEngine->m_PhysXComponent->addActor(_pXactor);
}

The crash report looks like this:

Unhandled exception at 0x0F75464E (PhysX3Common_x86.dll) in PhysicsPhysX.exe: 0xC0000005: Access violation reading location 0x000000B0.

But I assume it’s basically just telling me that the pointer to the mesh is invalid? Which is presumably what is triggering the double deletion error in the console? I really need a fix for this as I need to be able to build my project in release.

It’s been two weeks since i posted this and no response from anyone? I’m just wondering if it’s a bug in PhysX or my code? My executable is 32bit Windows BTW. Note again that I can run the debug version fine, it’s only when I try to run the release that I get this bug. I guess I could try linking against all the debug libraries in release just to be sure it’s not my code. I’ll try that but some advise from the dev team wouldn’t go a miss in a case like this :(

So I linked against the debug libraries and now I see the following errors in the console:

…\GeomUtils\src\mesh\GuTriangleMesh.cpp (98) : invalid operation : Gu::Trian
gleMesh::release: double deletion detected!

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

…\PhysX\src\NpScene.cpp (375) : warning : PxScene::addActor(): Static actor
with no shapes added to scene

One for each mesh I try to add to PhysX. But I don’t see this error and everything works fine in debug. I guess this might mean the bug is in my code somewhere as that’s the only thing different between working and not working? But I am still no closer to working out where the bug might be. I get the same error with any mesh I try, even obj and FBX which I am loading in and work fine in other frameworks.

The warnings do suggest that something is wrong with the data you feed to createShape. In debug build physx just returns without crashing when it realises that something is wrong. In release build, however, physx carries on regardless and can crash if the input data is illegal. The quickest way to find out what is wrong is to step into the function in the debugger.

I can’t see anything obvious in your code but this line did stand out:

assert(caveEngine->m_PhysXComponent->g_PhysicsCooker->cookTriangleMesh(meshDesc, *buf));

Does this mean you are only calling cookTriangleMesh in debug build?

Cheers,

Gordon

That’s it! I feel like such an idiot. I looked at that code and never thought about that. Yep removing the assert has solved the problem.

Thanks Gordon!