0
PxTriangleMesh* PhysX::CreateTriangleMesh(const PxVec3* verts, const PxU32 numVerts
    , const PxU32* indexs, const PxU32 numIndexes, PxPhysics* physics, PxCooking* cooking)
{
    // Create descriptor for triangle mesh
    PxTriangleMeshDesc meshDesc;
    meshDesc.points.count = numVerts;
    meshDesc.points.stride = sizeof(PxVec3);    
    meshDesc.points.data = verts;

    meshDesc.triangles.count = numIndexes / 3;
    meshDesc.triangles.stride = 3 * sizeof(PxU32);
    meshDesc.triangles.data = indexs;

    // for prevent stackoverflow
    PxU32 estimatedVertSize = numVerts * sizeof(PxVec3) * 1.5;
    PxU32 estimatedIndexSize = numIndexes * sizeof(PxU32) * 1.5;
    PxU32 initialSize = estimatedVertSize + estimatedIndexSize;
    CustomPhysXMemory writeBuffer(initialSize);

    //PxDefaultMemoryOutputStream writeBuffer;
    bool status = cooking->cookTriangleMesh(meshDesc, writeBuffer);
    if (!status)
        return nullptr; 

    PxDefaultMemoryInputData readBuffer(writeBuffer.getData(), writeBuffer.getSize());
    PxTriangleMesh* triangleMesh = physics->createTriangleMesh(readBuffer);

    return triangleMesh;
}

I want to give a collider to mesh that load by assimp so I made a physX triangleMesh. In many situations, it works But sometimes in cookTriangleMesh Exception thrown at 0x00007FFD322F259E (PhysXCooking_64.dll) in Client.exe: 0xC0000005: Access violation reading location 0x0000019F69AA8000. occurs.

I was worried about the capacity of buffer and gave him a 1.5 times space, and I checked ((physx::PxSimpleTriangleMesh)&meshDesc),nd {points={count=82772 } triangles={count=43798 } flags={mBits=0 } } writeBuffer.mBuffer.capacity() 2278260 These two always came out the same either success or failure..

So I don't have a clue what the problem is. Can someone who knows the problem and how to solve it help me?

1 Answer 1

0

This is not a problem which is related to Assimp. I checked the Physix-API and I was wondering why you have calculated a initial size.

In this example the writebuffer was not initialided: Physix Example

Maybe this would be an option for you? And I strongly recommend to use the validation methods to get more information aabout your issue:

#ifdef _DEBUG
    // mesh should be validated before cooked without the mesh cleaning
    bool res = theCooking->validateTriangleMesh(meshDesc);
    PX_ASSERT(res);
#endif

PxTriangleMesh* aTriangleMesh = theCooking->createTriangleMesh(meshDesc,
thePhysics->getPhysicsInsertionCallback());

Hope that helps a little bit.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.