Releasing a vertex buffer

Started by
2 comments, last by Briskon 20 years, 9 months ago
I've been going through the DirectX 8.1 sdk and I have a problem with the section on Shadow volumes. During the initialization stage the terrain is operated on to give it a bit or random displacement in the y axis.

///////////////////*****************//////////////


m_pTerrainObject->SetFVF( m_pd3dDevice, D3DFVF_VERTEX ); 
{
LPDIRECT3DVERTEXBUFFER8 pVB;
VERTEX* pVertices;
DWORD dwNumVertices = m_pTerrainObject->GetSysMemMesh()->GetNumVertices();

m_pTerrainObject->GetSysMemMesh()->GetVertexBuffer( &pVB );
pVB->Lock(0, 0, (BYTE**)&pVertices, 0);
for ( DWORD i=0; i < dwNumVertices; i++ )
{
  pVertices[i].p.y += 1*(rand()/(FLOAT)RAND_MAX);
  pVertices[i].p.y += 2*(rand()/(FLOAT)RAND_MAX);
  pVertices[i].p.y += 1*(rand()/(FLOAT)RAND_MAX);
}
pVB->Unlock();
pVB->Release();
}
After the vertex buffer is retrieved, and the vertices are operated on, the vertex buffer is released??????? How can this work, if the vertex buffer is released the vertices should no longer exist and therefore when it comes to rendering, there should be nothing to render........ Obviously it does work, but I can't understand why? (All I can think of is that the COM ref count is incremented when GetVertexBuffer is called?) Can anyone help me with this. [/source]
Advertisement
The COM ref count is, in fact, incremented on GetVertexBuffer.
the pVertices is an array that is fillesd with the vertecies data and used after that in rendering .
You''d think Microsoft would mention that somewhere in the SDK, wouldn''t you.

pVertices is only in scope for this segment of code, therefore when this segment finishes, pVertices no longer points to valid data.

This topic is closed to new replies.

Advertisement