• ### Announcements

#### Archived

This topic is now archived and is closed to further replies.

# Releasing a vertex buffer

## Recommended Posts

Briskon    122
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]

##### Share on other sites
Guest Anonymous Poster
The COM ref count is, in fact, incremented on GetVertexBuffer.

##### Share on other sites
the pVertices is an array that is fillesd with the vertecies data and used after that in rendering .