Jump to content
  • Advertisement


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


Locking VB crash

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

In my mesh class, I use the following function to add vertices to the vb. This is done after the model data has been loaded from the file. The problem is that after several iterations (I use this in a for loop), the function crashes on the memcpy method.
HRESULT AddVertex(CRTMesh* pMesh, const Vec3& vVertex, const Vec3& vNormal, float tu, float tv, bool newGroup)
	if ( !pMesh)

	rtMesh* mesh = pMesh->GetStruct();

    DWORD iDataSize = sizeof(RTVERTEX2);


	RTVERTEX2* pVertices = NULL;
	ver.CreateVertex (vVertex, vNormal, tu, tv);

	if (newGroup)
		rtMeshGroup gr;

		gr.VertexStart = mesh->iNextVertexData;
		gr.VertexCount = 0;
		gr.bUseDetail = gr.bSphereMap = false;
		gr.Radius = 0.0f;
		gr.SphereCenter = Vec3(0,0,0);
		gr.MaxBox = gr.MinBox = Vec3(0,0,0);
		gr.pTexture = gr.pDetail = NULL;
		gr.pMaterial = NULL;
		mesh->nMaterials ++;
	if (FAILED(mesh->pVB->Lock(mesh->iNextVertexData, iDataSize, (void**)&pVertices, D3DLOCK_NOOVERWRITE)))
		return RT_FAIL_VBLOCK;
				CopyMemory (pVertices, (void*)&ver, sizeof(RTVERTEX2));
	if (FAILED(mesh->pVB->Unlock()))

	mesh->iNextVertexData += iDataSize;
	mesh->nVertices ++;

	return RT_OK;
The vb size can hold the vertices, the pool is dynamic and as you see I am locking it every one vertex I add. I know this isnt efficient, but it shouldnt crash, right? iNextVertexData initially is zero as it should be, what am I doing wrong here? (sorry if the formatting has gone weird..)

Share this post

Link to post
Share on other sites

I create the VB:

dev->CreateVertexBuffer (wVertexCount * sizeof(RTVERTEX2),

(I am not using X files).

Share this post

Link to post
Share on other sites

Did you try debugging? What are the return codes on all your function calls?

My guess is that you''re going over the size limit of the buffer, that happens a lot and produces that nasty blip of a program execution.

Share this post

Link to post
Share on other sites
Found it, it wasnt entirely my fault. I was loading an MS3D file, and it is apparently using indexed tri lists for storing its data. I am using tri lists, and my vertex count needed to be 3 * tri count, whereas the MS3D vertex count was about half of the tris.

And believe me, I have tried everything, I got it working now, thanks.

Share this post

Link to post
Share on other sites

  • 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!