문제

I am using PhysX, OpenGL and assimp. I am getting 'unhandled exception ..... Access violation reading location 0x00000' at the last line

void CreateActor(const aiScene *scene)
{
NxTriangleMeshDesc t;
aiMesh *mesh = scene->mMeshes[0];
t.numVertices = mesh->mNumVertices;
t.points = mesh->mVertices;
t.pointStrideBytes = sizeof(aiVector3D);
t.numTriangles = mesh->mNumFaces;
NxU32 *tr = new NxU32[mesh->mNumFaces*3];
NxU32 k=0;
for(NxU32 i=0;i<mesh->mNumFaces;i++)
    for(int j=0;j<3;j++)
        tr[k++]=mesh->mFaces[i].mIndices[j];
t.triangles = tr;
t.triangleStrideBytes = sizeof(NxU32)*3;
t.flags=0;
NxTriangleMeshShapeDesc terrainShapeDesc; 

 // Cooking from memory
 InitCooking();
 MemoryWriteBuffer buf;
 bool status = CookTriangleMesh(t, buf);
 MemoryReadBuffer readBuffer(buf.data);
 gPhysicsSDK->createTriangleMesh(readBuffer);
}

Using Assimp::Importer I have read a simple cube in .x It has 24 vertices, 12 faces. point of using 2 for loops with 'mesh->mFaces[i].mIndices[j]' is that there is a mNumIndices algong with mIndices

I know the function CreateActor is incomplete, but the error was on the 'createTriangleMesh' (last line) so I omitted rest.

도움이 되었습니까?

해결책

The gPhysicsSDK was NULL, so that was the whole problem. For anyone who uses PhysX and wish to load various 3D models (.3DS, .X, .obj, etc) you can find the above code handy (except you'll have to loop through all aimesh), google assimp.
Thanks Tyler

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top