Skip to main content
gamedev.net
🔒 Locked

Problems locking VB

Started by thedo Mar 21, 2003 at 4:02 PM 2 replies 300+ views
Original Post
thedo
thedo
I am implementing a vertex cache system but have hit a problem. Heres the code thn I''ll explain: In my vertex cache
  
void CVertexCache::Fill(void *pVertices,UINT pNumVertices,void *pIndices,UINT pNumIndices)
{
	void *pBits=NULL;
	m_pVB->Lock(m_numVertices*m_stride,pNumVertices*m_stride,&pBits,0);
		memcpy(pBits,pVertices,pNumVertices*m_stride);
	m_pVB->Unlock();

	pBits=NULL;
	m_pIB->Lock(m_numIndices*sizeof(WORD),pNumVertices*sizeof(WORD),&pBits,0);
		memcpy(&pBits,pIndices,pNumIndices*sizeof(WORD));
	m_pIB->Unlock();

	m_numVertices+=pNumVertices;
	m_numIndices+=pNumIndices;
}
  
and is called like:
  
FinalMesh->LockVertexBuffer(0,&verts);
	FinalMesh->LockIndexBuffer(0,&inds);
	m_pVertexCache->Fill(verts,FinalMesh->GetNumVertices(),inds,FinalMesh->GetNumFaces()*3);
	FinalMesh->UnlockIndexBuffer();
	FinalMesh->UnlockVertexBuffer();
  
Now when it gets to the
memcpy(pBits,pVertices,pNumVertices*m_stride);
 
it fails. I''ve checked all HRESULTS (all S_OK), debug doesnt help as it only happens in release mode (in D3D control panel app). Is there anything obvious I''m doing/not doing that anyone might recommend? I''ve been looking at this error for about a week and am tearing my hair out (whats left of it anyway)/ Cheers Neil WHATCHA GONNA DO WHEN THE LARGEST ARMS IN THE WORLD RUN WILD ON YOU?!?!
WHATCHA GONNA DO WHEN THE LARGEST ARMS IN THE WORLD RUN WILD ON YOU?!?!
Bilgates
Bilgates
For one thing pBits shouldn''t be set to NULL. So
m_pVB->Lock(m_numVertices*m_stride,pNumVertices*m_stride,&pBits,0);
should fail since pBits points to nothing and it should.
thedo
thedo
That didnt sort it out unfortunately.

I noticed this in the docs
quote:

A limitation of the Windows2000 Kernel can result in some resources being freed while the resource is locked and being accessed by the application.

This results in the app writing to freed memory, causing an exception




Now my VB and IB are D3DPOOL_MANAGED (which should be OK).

This is how I load my mesh:


  
LPD3DXMESH LoadMesh,FinalMesh;
LPD3DXBUFFER AdjacencyBuffer=NULL,MtrlBuffer=NULL;
D3DXLoadMeshFromX(Filename,D3DXMESH_MANAGED,m_pDevice,&AdjacencyBuffer,
&MtrlBuffer,NULL,&m_nTexture,&LoadMesh);
LoadMesh->CloneMeshFVF(D3DXMESH_SYSTEMMEM,D3DFVF_XYZ|D3DFVF_NORMAL|D3DFVF_TEX0,m_pDevice,&FinalMesh);
D3DXComputeNormals(FinalMesh, (DWORD*)AdjacencyBuffer->GetBufferPointer());
FinalMesh->OptimizeInplace(D3DXMESHOPT_ATTRSORT,(DWORD*)AdjacencyBuffer->GetBufferPointer(),
NULL, NULL,NULL);


Now there doesnt seem to be a D3DXMESH_POOLDEFAULT but does D3DXMESH_SYSTEMMEM produce similar errors in anyones experience?

Cheers

Neil


WHATCHA GONNA DO WHEN THE LARGEST ARMS IN THE WORLD RUN WILD ON YOU?!?!
WHATCHA GONNA DO WHEN THE LARGEST ARMS IN THE WORLD RUN WILD ON YOU?!?!
thedo
thedo
I got to the bottom of it:

When I cloned my Mesh i specified the FVF of
(D3DFVF_XYZ|D3DFVF_NORMAL|D3DFVF_TEX0)

but the VB had an FVF of
(D3DFVF_XYZ|D3DFVF_NORMAL|D3DFVF_TEX1)

which seemed to give the whole thing a bit of a headache.

Thanks anyway.

Neil

WHATCHA GONNA DO WHEN THE LARGEST ARMS IN THE WORLD RUN WILD ON YOU?!?!
WHATCHA GONNA DO WHEN THE LARGEST ARMS IN THE WORLD RUN WILD ON YOU?!?!

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.