Advertisement Jump to content
Sign in to follow this  

Problem with Index Buffer

This topic is 4851 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)

	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);	

	HRESULT hr = pMeshData->pMesh->LockIndexBuffer(0,  (void**)&pIndexData); //ERROR: D3DXERR_CANNOTMODIFYINDEXBUFFER

		buildVertexInfo(pBuffRes, (DWORD*)pIndexData);

	while(m_bHasUncontainedVertexes) //build a generation of child spheres

Share this post

Link to post
Share on other sites
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, you agree to our community Guidelines, Terms of Use, and Privacy Policy. is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!