Jump to content
  • Advertisement
Sign in to follow this  
Alx666_IT

Problem with Index Buffer

This topic is 4666 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

Hi..i'm going to write an algorithm to build a sphere tree to use for collision detection purposes. Since i want to store geometry information in the leaf-spheres of the tree i'm extracting vertex/index data from the source mesh for leater elaboration. Anyway, problem is that LockIndexBuffer returns to me D3DXERR_CANNOTMODIFYINDEXBUFFER. The problem is nested on the first step of the algorithm where i'm accessing both the vertex buffer and the index buffer to elaborare them to build a new buffer leaked of all the information unuseful for the purposes
void  SCBoundingSphere::buildTree(const D3DXMESHDATA* pMeshData)
{
	if(m_fRadius == 0.0f)
		buildSphere(pMeshData);

	DWORD dwNumVertices, dwStride;
	void* pVertexData = 0; //to access vertex data
	DWORD* pIndexData = 0; //to access index data
	D3DXVECTOR3* pBuffRes; //temp storage for vertex, to convert in VertexInfo

	dwNumVertices	= pMeshData->pMesh->GetNumVertices();
	m_dwIndexCount  = pMeshData->pMesh->GetNumFaces() * 3;
	dwStride		= pMeshData->pMesh->GetNumBytesPerVertex();

	pMeshData->pMesh->LockVertexBuffer(NULL, (void**)&pVertexData);
		pBuffRes = isolateVertexData((D3DXVECTOR3*)pVertexData, dwNumVertices, dwStride);	
	pMeshData->pMesh->UnlockVertexBuffer();

	HRESULT hr = pMeshData->pMesh->LockIndexBuffer(0,  (void**)&pIndexData); //ERROR: D3DXERR_CANNOTMODIFYINDEXBUFFER
	if(hr == D3DXERR_CANNOTMODIFYINDEXBUFFER)
		MessageBox(NULL, "D3DXERR_CANNOTMODIFYINDEXBUFFER", "Error", MB_OK);		

		buildVertexInfo(pBuffRes, (DWORD*)pIndexData);
	pMeshData->pMesh->UnlockIndexBuffer();
	

	while(m_bHasUncontainedVertexes) //build a generation of child spheres
		addSubSphere();
}

Share this post


Link to post
Share on other sites
Advertisement
Try changing the call to
pMeshData->pMesh->LockIndexBuffer(D3DLOCK_DISCARD ...

and see if that does anything

Share this post


Link to post
Share on other sites
Also, try locking with D3DLOCK_READONLY, it might not be allowing you to modify the data (you only want to read the data, right?).

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!