Cannot get basic importer working.
I'm trying to just get some kind of import plugin working in xNormal, but it isn't working. Every time I attempt to use the plugin, it says, "Attempted to read or write protected memory. This is often an indication that other memory is corrupt."
From Logging, I can tell that tis error happens after I "load" the mesh.
Note that the plugin doesn't load anything. All it does is create the same mesh whenever it is invoked. It's a simple quad with texture coordinates. Just positions and texcoords.
Am I building the PolyMesh incorrectly? Here's the code:
Utils::Log(L"Processing:\n");
PolyMesh *pMesh = geom.AddPolyMesh();
pMesh->SetName ( L"no name" );
pMesh->ReservePoints(4);
Utils::Log(L"Reserved Points.\n");
pMesh->AddPoint(Vector(1, 1, 0));
pMesh->AddPoint(Vector(-1, 1, 0));
pMesh->AddPoint(Vector(-1, -1, 0));
pMesh->AddPoint(Vector(1, -1, 0));
pMesh->ReserveUVs(4);
Utils::Log(L"Reserved UVs.\n");
pMesh->AddUV(Vector2(1, 1));
pMesh->AddUV(Vector2(0, 1));
pMesh->AddUV(Vector2(0, 0));
pMesh->AddUV(Vector2(1, 0));
PolyMesh::Face faces[2];
faces[0].SetNVerts(3);
faces[1].SetNVerts(3);
faces[0].SetVertexIdx(0, 0);
faces[0].SetVertexIdx(0, 1);
faces[0].SetVertexIdx(0, 2);
faces[1].SetVertexIdx(0, 0);
faces[1].SetVertexIdx(0, 2);
faces[1].SetVertexIdx(0, 3);
Utils::Log(L"Built Faces.\n");
pMesh->ReservePointFaces(2);
pMesh->ReserveUVFaces(2);
Utils::Log(L"Faces Reserved.\n");
pMesh->AddPointFace(faces[0]);
pMesh->AddPointFace(faces[1]);
pMesh->AddUVFace(faces[0]);
pMesh->AddUVFace(faces[1]);
Utils::Log(L"Done.\n");
I'm using VC8, SP1, in a release build.
Any ideas what I'm doing wrong?
1. The ReserveXXXXXXXX/AddXXXXXXXXX combo is ok, but usually is more efficient to use ResizeXXXXXXX instead . It works exactly like STL's containers.
This is a small example to fill the points:
pMesh->ResizePoints(4U);
pMesh->SetPoint ( 0U, (Vector(1.0f, 1.0f, 0.0f) );
pMesh->SetPoint ( 1U, Vector(-1.0f, 1.0f, 0.0f) );
pMesh->SetPoint ( 2U, Vector(-1.0f, -1.0f, 0.0f) );
pMesh->SetPoint ( 3U, Vector(1.0f, -1.0f, 0.0f) );
2.
faces[0].SetVertexIdx ( 0, 0 );
faces[0].SetVertexIdx ( 0, 1 );
faces[0].SetVertexIdx ( 0, 2 );
Nope !!!!!!!!!!!!!!!!! Correct is:
faces[0].SetVertexIdx ( 0U, 0U );
faces[0].SetVertexIdx ( 1U, 2U );
faces[0].SetVertexIdx ( 2U, 3U );
The first index is the vertex index inside the face's indices. If you use a trianglethe range is [0U,2U]. For a quad [0U,3U].
The second parameter is the vertex index relative to the mesh's vertex list, in range [0U, msh.GetNumPoints/Normals/UVs/etc()-1U]
Also, pls notice you must use the predefined macro _SECURE_SCL=0 in release mode.
Do NOT compiple using debug mode because xNormal is deployed in release mode and the C CRT won't match, causing tons of problems.
If you need to debug set a Release mode, disable optimizations and enable custom asserts. And only VC++ 2008 SP1 is supported atm ( VS2010 might work or not, depending on your code, exceptions and STL usage ). this is a thing we wanna fix in xn4.
Yep, that was it. The importer works now. Thanks!






Oh, I'm using xNormal version 3.17.8, and I've made sure that the SDK version matches (with: `XNORMAL_SDK_VERSION==host.GetSDKVersion()`).