Archived

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

Releasing a vertex buffer

This topic is 5276 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

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 this post


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

Share this post


Link to post
Share on other sites
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.

Share this post


Link to post
Share on other sites