Hello i just started with PhysX, so far most things worked fine but now i'm trying to create PxTriangleMeshGeometry and my program crashes like 70% of the time. I followed the example from manual, basicly here's my code:
// i'm using _mm_malloc 16 because i tough this may be the problem
// but it didn't help
PxVec3 *pVert = (PxVec3*)_mm_malloc(sizeof(PxVec3)*(v_verticles.size()), 16);
PxU32 *pIndex = (PxU32*)_mm_malloc(sizeof(PxU32)*(_indices.size()), 16);
for (UINT i = 0; i < v_verticles.size(); i++)
pVert[i] = PxVec3(v_verticles[i].x, v_verticles[i].y, v_verticles[i].z);
for (UINT i = 0; i < _indices.size(); i++)
pIndex[i] = _indices[i];
PxTriangleMeshDesc meshDesc;
meshDesc.points.count = v_verticles.size();
meshDesc.points.stride = sizeof(PxVec3);
meshDesc.points.data = pVert;
meshDesc.triangles.count = _indices.size();
meshDesc.triangles.stride = 3 * sizeof(PxU32);
meshDesc.triangles.data = pIndex;
// application crashes here on validateTriangleMesh
// also when the application doesn't crash, it always returns invalid
if (!in_gameMap->m_pxCooking->validateTriangleMesh(meshDesc))
debugMsg("invalid");
else
debugMsg("valid");
PxDefaultMemoryOutputStream writeBuffer;
if (in_gameMap->m_pxCooking->cookTriangleMesh(meshDesc, writeBuffer))
{
PxDefaultMemoryInputData readBuffer(writeBuffer.getData(), writeBuffer.getSize());
m_pxTriMesh = in_gameMap->m_pxPhysics->createTriangleMesh(readBuffer);
PxShapeFlags shapeFlags = PxShapeFlag::eSCENE_QUERY_SHAPE | PxShapeFlag::eSIMULATION_SHAPE;
PxTriangleMeshGeometry cmg(m_pxTriMesh);
m_pxShape = in_gameMap->m_pxPhysics->createShape(cmg, *m_pxMaterial, 1, shapeFlags);
}
When i simply remove validateTriangleMesh, application crashes later on cookTriangleMesh. Also I'm using PxConvexMesh for cylinders, app doesn't crash on this but validateConvexMesh also returns false.
PxVec3 *pVert = (PxVec3*)_mm_malloc(sizeof(PxVec3)*32, 16);
for (int i = 0; i < 16; i++)
{
pVert[i * 2] = PxVec3(sin(i*XM_2PI / 16.0f)*in_halfExtents->x, in_halfExtents->y, cos(i*XM_2PI / 16.0f)*in_halfExtents->z);
pVert[i * 2 + 1] = PxVec3(sin(i*XM_2PI / 16.0f)*in_halfExtents->x, -in_halfExtents->y, cos(i*XM_2PI / 16.0f)*in_halfExtents->z);
}
PxConvexMeshDesc convexDesc;
convexDesc.points.count = 32;
convexDesc.points.stride = sizeof(PxVec3);
convexDesc.points.data = pVert;
convexDesc.flags = PxConvexFlag::eCOMPUTE_CONVEX;
if (!in_pxCooking->validateConvexMesh(convexDesc))
debugMsg("invalid validateConvexMesh");
PxDefaultMemoryOutputStream buf;
if (!in_pxCooking->cookConvexMesh(convexDesc, buf))
{
_mm_free(pVert);
return 0;
}
Why dos my application crash and why is validateConvexMesh returning false?