Sign in to follow this  
QuadMV

wrong results in indexbuffer

Recommended Posts

I’m using DirectX 9, and working with .X files using D3DXLoadMeshHierarchyFromX. I’m locking a mesh index and vertex buffer, but I seem to be getting the wrong values out of the index buffer. I’m hoping someone can tell me what stupid thing I’m missing. I’m calling: hr=pMesh->LockIndexBuffer(D3DLOCK_READONLY, (void**)&indexPtr); hr=pMesh->LockVertexBuffer(D3DLOCK_READONLY, (void**)&vertPtr); Then I’m looking at indexPtr[0] to grab the first element out of the vertex buffer, something like: X = ((int *)vertPtr)[ ((int *)indexPtr)[0] ] Which is failing because ((int *)indexPtr)[0] is returning a value way outside the bounds of vertPtr. If I manually look at vertPtr[0] or [1] or [2] they look reasonable However, when I look at indexPtr[0] it’s not even close. The entire object has maybe a couple hundred vertices, but indexPtr[0] is returning some value like 196609, [1] = 131074 and [2] = 65536, then [3] … are all 0 I know this is wrong, but I don’t know why. I think everything looks clean. Does anyone have any idea what might be wrong here? FYI, the mesh renders fine. Thanks

Share this post


Link to post
Share on other sites
What is the declaration for indexPtr?

Depending on the mesh (check ID3DXMesh::GetOptions() for D3DXMESH_32BIT) it'll either be an unsigned 32bit or 16bit integer. If you use the wrong type then the casting will just mess up your numbers [smile]

They're MS specific i think, but using unsigned __int16* or unsigned __int32* pointers should guarantee you get the right quantity (using the compilers native int/short types should work, but isn't guaranteed).

Also, are you sure that the calls are succeeding? if LockIndexBuffer() fails then you could just be using garbage from a random point in memory...

hth
Jack

Share this post


Link to post
Share on other sites
The lock call is succeeding, that was the first thing I checked.

Using __int16 is producing better results but it’s not perfect, however, that might be a different problem on my side (I think I know what it is). I just tried the __int16 as a quick test. Let me try the GetOptions and see what it reports.

Thanks

Share this post


Link to post
Share on other sites
I created a struct to use with my index buffers:

struct Indice
{
WORD a, b, c;
};

Then to access it in the code:

Indice* pI;
pMesh->LockIndexBuffer(0, (LPVOID*)&pI);

int pos = pI[index].a; // get index to the first vertex for this face




Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this