Another "Direct3D Device Lost!"-error with vertex-buffers

Problems building or running the engine, queries about how to use features etc.
Post Reply
PhilipLB
Google Summer of Code Student
Google Summer of Code Student
Posts: 550
Joined: Thu Jun 04, 2009 5:07 pm
Location: Berlin

Another "Direct3D Device Lost!"-error with vertex-buffers

Post by PhilipLB » Wed Oct 14, 2009 4:13 pm

Hi,

if I lose the Direct3D-device (Ctrl-Alt-Del and return in Vista for example), my program crashes. This is due to some vertex- and index-buffers I create and fill in the loading-phase and never touch them again.
I heard that I somehow need to refresh them, but how and when?
Here is, how I create my data:

Code: Select all


	mRenderOp.operationType = RenderOperation::OT_TRIANGLE_LIST;
	mRenderOp.vertexData = new VertexData();
	mRenderOp.vertexData->vertexCount = hmm.getVertexCount();
	mRenderOp.vertexData->vertexStart = 0;

	// Get Vertexdata
	VertexDeclaration *decl = mRenderOp.vertexData->vertexDeclaration;
	VertexBufferBinding *bind = mRenderOp.vertexData->vertexBufferBinding;

	size_t offset = 0;

	// Add vertex-positions to the buffer
	decl->addElement(0, offset, VET_FLOAT3, VES_POSITION);
	offset += VertexElement::getTypeSize(VET_FLOAT3);

	// Add blending-weight to the buffer
	decl->addElement(0, offset, VET_FLOAT4, VES_BLEND_WEIGHTS);
	offset += VertexElement::getTypeSize(VET_FLOAT4);

	// Add vertex-normals to the buffer
	decl->addElement(0, offset, VET_FLOAT3, VES_NORMAL);
	offset += VertexElement::getTypeSize(VET_FLOAT3);

	// Add texture-coordinates to the buffer
	decl->addElement(0, offset, VET_FLOAT2, VES_TEXTURE_COORDINATES);
	offset += VertexElement::getTypeSize(VET_FLOAT2);

	// Add a second set of texture-coordinates to the buffer
	decl->addElement(0, offset, VET_FLOAT2, VES_TEXTURE_COORDINATES, 1);
	offset += VertexElement::getTypeSize(VET_FLOAT2);

	HardwareVertexBufferSharedPtr vbuf =
	HardwareBufferManager::getSingleton().createVertexBuffer(
		decl->getVertexSize(MAIN_BINDING),
		mRenderOp.vertexData->vertexCount,
		HardwareBuffer::HBU_STATIC_WRITE_ONLY);

	bind->setBinding(0, vbuf);

	Real* vertices = static_cast<Real*>(vbuf->lock(HardwareBuffer::HBL_DISCARD));

	// Fill data.
	hmm.generateVertices(useHeightFrom, vertices, splatMapTiles);
	vbuf->unlock();

	// Get Indexarray
	mRenderOp.indexData = new IndexData();
	mRenderOp.indexData->indexCount = hmm.getIndexCount();
	mRenderOp.indexData->indexStart = 0;

	mRenderOp.indexData->indexBuffer =
		HardwareBufferManager::getSingleton().createIndexBuffer(
		HardwareIndexBuffer::IT_32BIT,
		mRenderOp.indexData->indexCount, HardwareBuffer::HBU_STATIC_WRITE_ONLY);

	unsigned int* indices = static_cast<unsigned int*>(
			mRenderOp.indexData->indexBuffer->lock(0,
			mRenderOp.indexData->indexBuffer->getSizeInBytes(),
		HardwareBuffer::HBL_DISCARD));

	// Fill data.
	hmm.generateIndices(indices);
	mRenderOp.indexData->indexBuffer->unlock();
0 x
Google Summer of Code 2012 Student
Topic: "Volume Rendering with LOD aimed at terrain"
Project links: Project thread, WIKI page, Code fork for the project
Mentor: Mattan Furst


Volume GFX, accepting donations.

PhilipLB
Google Summer of Code Student
Google Summer of Code Student
Posts: 550
Joined: Thu Jun 04, 2009 5:07 pm
Location: Berlin

Re: Another "Direct3D Device Lost!"-error with vertex-buffers

Post by PhilipLB » Thu Oct 15, 2009 10:00 am

Sorry, the error must be somewhere else. I commented all mesh-code so the scene stays empty and the error still occurs. Currently investigating...
0 x
Google Summer of Code 2012 Student
Topic: "Volume Rendering with LOD aimed at terrain"
Project links: Project thread, WIKI page, Code fork for the project
Mentor: Mattan Furst


Volume GFX, accepting donations.

PhilipLB
Google Summer of Code Student
Google Summer of Code Student
Posts: 550
Joined: Thu Jun 04, 2009 5:07 pm
Location: Berlin

Re: Another "Direct3D Device Lost!"-error with vertex-buffers

Post by PhilipLB » Thu Oct 15, 2009 11:17 am

Fixed it. :)
Reason:
I hold a pool of HardwareOcclusionQueries to be able to reuse them. A HardwareOcclusionQuery gets invalid if the device is lost.
Solution:
My OcclusionQueryPool is now a RenderSystemListener. On DeviceLost, the pool get's destroyed and on DeviceRestored, I build it up again.
0 x
Google Summer of Code 2012 Student
Topic: "Volume Rendering with LOD aimed at terrain"
Project links: Project thread, WIKI page, Code fork for the project
Mentor: Mattan Furst


Volume GFX, accepting donations.

Post Reply