Vertex Buffer overrun

Started by
2 comments, last by Matias Goldberg 8 years, 10 months ago

Does anyone have an idea why the vertex buffer would overrun? Thanks Jack


// load vertex into m_verts
    LPDIRECT3DVERTEXBUFFER9 pVBuf;
    if (SUCCEEDED(m_pMesh->GetVertexBuffer(&pVBuf))) {
        CUSTOMVERTEX *pVert;
        if (SUCCEEDED(pVBuf->Lock(0, 0, (LPVOID *)&pVert, D3DLOCK_DISCARD))) {
            DWORD numVerts = m_pMesh->GetNumVertices();
            for (int i = 0; i<numVerts; i++) {                
                float x = pVert[i].x;
                float y = pVert[i].y;
                float z = pVert[i].z;
                pVert++;
                addVertex(x, y, z, vcap);
                
            }
            pVBuf->Unlock();
        }
        pVBuf->Release();
    }
Advertisement

I don't know if that's the only issue, but locking a buffer with D3DLOCK_DISCARD and then reading from it is not a valid operation.

Many possible reasons, vertex buffer might be too small, there might be a different vertex format.

But most likely... you're incrementing your offset twice - once on "i++" and the second time on "pVert++;". Either remove the second one or treat pVert as the pointer to current vertex ("pVert.x" -> "pVert->x" etc.)

I don't know if that's the only issue, but locking a buffer with D3DLOCK_DISCARD and then reading from it is not a valid operation.

Fun fact: It actually was valid in Windows XP and some games relied on the flag doing nothing (and then they broke on Vista/7/8 and I had to make a proxy DLL to play them).

There's a lot of information missing.

sizeof(CUSTOMVERTEX) could be wrong.

The vertex buffer could be smaller than sizeof(CUSTOMVERTEX) * numVerts;

Also whatever happens inside addVertex could be causing stack corruption. A lot of unknown variables to say.

I don't know if that's the only issue, but locking a buffer with D3DLOCK_DISCARD and then reading from it is not a valid operation.

Fun fact: It actually was valid in Windows XP and some games relied on the flag doing nothing (and then they broke on Vista/7/8 and I had to make a proxy DLL to play them).

It was invalid then, still invalid now. It "just worked" doesn't mean it was valid. Many games violate the API rules.

This topic is closed to new replies.

Advertisement