• Advertisement
Sign in to follow this  

Lock Access Violation Help

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

Hey I was wondering if anyone could shed some light onto this one

 

I'm trying to lock my vertex buffer and index buffer like so:

vBuffer->Lock(currentVertexDataAmount, vertexBufferSize - currentVertexDataAmount, (void**)&vertices, bufferLockFlag);
iBuffer->Lock(currentIndexDataAmount, indexBufferSize - currentIndexDataAmount, (void**)&indices, bufferLockFlag);
	

But I always get a Access Violation on the vertex buffer unlock call after the second run though. It definitely has something to do with the offset and sizeToLock params.

On the second run through there is a starting offset of 96 (One quad vertex data worth) and 192 (2 quads vertex data worth) as the sizeToLock.

If I set the params to 0, 0 it works. But I would like to only lock what I need

 

Any ideas? Am I just using the offset and sizeToLock params wrong or is everything wrong?

The lock flag is set to NOOVERWRITE at the start.

 

Here is how this code is being used

        vBuffer->Lock(currentVertexDataAmount, vertexBufferSize - currentVertexDataAmount, (void**)&vertices, bufferLockFlag);
	iBuffer->Lock(currentIndexDataAmount, indexBufferSize - currentIndexDataAmount, (void**)&indices, bufferLockFlag);
	
	for(std::vector<quad>::iterator i = drawData.begin(); i != drawData.end(); i++)
	{
                //If the vertex buffer is full
		if(vertexBufferSize - currentVertexDataAmount == 0)
                {

                vBuffer->Unlock(); //<----- [ BREAK HAPPENS HERE after second run through ]
                iBuffer->Unlock();

                /*
                   Draw what needs to be drawn;
                   Set the positions of the buffers and data amount used to 0;
                   change the lock flag to DISCARD;
                */

                vBuffer->Lock(currentVertexDataAmount, vertexBufferSize - currentVertexDataAmount, (void**)&vertices, bufferLockFlag);
                iBuffer->Lock(currentIndexDataAmount, indexBufferSize - currentIndexDataAmount, (void**)&indices, bufferLockFlag);
                  
                /*change the lock flag back to NOOVERWRITE*/
                }
                 

                //Fill the vertex buffer
		vertices[currentVertexBufferPosition] = (*i).verts[0];
		vertices[currentVertexBufferPosition + 1] = (*i).verts[1];
		vertices[currentVertexBufferPosition + 2] = (*i).verts[2];
		vertices[currentVertexBufferPosition + 3] = (*i).verts[3];
                
                //Fill the vertex buffer
		indices[currentIndexBufferPosition] = currentVertexBufferPosition;
		indices[currentIndexBufferPosition + 1] = currentVertexBufferPosition + 1;
		indices[currentIndexBufferPosition + 2] = currentVertexBufferPosition + 2;
		indices[currentIndexBufferPosition + 3] = currentVertexBufferPosition + 3;
		indices[currentIndexBufferPosition + 4] = currentVertexBufferPosition;
		indices[currentIndexBufferPosition + 5] = currentVertexBufferPosition + 2;
                
                //Increase the data amounts
		currentVertexBufferPosition += 4;
		currentIndexBufferPosition += 6;
		currentVertexDataAmount += VERTEX_DATA_AMOUNT_PER_QUAD;
		currentIndexDataAmount += INDEX_DATA_AMOUNT_PER_QUAD;
                
                //Debug stuff
		std::cout<<"Added quad<> Y:"<<(*i).verts[0].y<<std::endl;
		std::cout<<"VB Pos: "<<currentVertexBufferPosition<<"; IB Pos: "<<currentIndexBufferPosition<<std::endl;
		getchar();

	}

	vBuffer->Unlock();
	iBuffer->Unlock();
        drawData.clear();
Edited by noodleBowl

Share this post


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

  • Advertisement