Jump to content

  • Log In with Google      Sign In   
  • Create Account

Interested in a FREE copy of HTML5 game maker Construct 2?

We'll be giving away three Personal Edition licences in next Tuesday's GDNet Direct email newsletter!

Sign up from the right-hand sidebar on our homepage and read Tuesday's newsletter for details!


#ActualnoodleBowl

Posted 24 October 2013 - 10:34 PM

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

#7noodleBowl

Posted 24 October 2013 - 10:30 PM

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. If I set those 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 ]
                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();

#6noodleBowl

Posted 24 October 2013 - 10:18 PM

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. If I set those 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();
                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();

#5noodleBowl

Posted 24 October 2013 - 10:15 PM

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. If I set those 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?

 

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

#4noodleBowl

Posted 24 October 2013 - 08:05 PM

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 unlock call after the second run though

Any ideas? Am I just using the offset and size to lock params wrong?

 

Here is a skeleton of 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(vertexBufferSize - currentVertexDataAmount == 0)
                {

                vBuffer->Unlock();
                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();

#3noodleBowl

Posted 24 October 2013 - 08:05 PM

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 unlock call after the second run though

Any ideas? Am I just using the offset and size to lock params wrong?

 

Here is a skeleton of 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++)
	{
		/* Check if the vertex buffer is full; */

                vBuffer->Unlock();
                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();

PARTNERS