VertexStride in stream 0 error

Started by
2 comments, last by Namethatnobodyelsetook 16 years, 5 months ago
I've been stuck on this error for a while and unable to solve it. The problem only occurs when running on the debug version of direct 3d9. My mesh will not render, and I get this error in the debug console. I am setting the vertex declaration explicitly before rendering, so Im not sure whats wrong. I get the same problem in a couple different places... On my custom mesh format that just uses buffers:

void Mesh::Render()
{
	dxDevice->SetVertexDeclaration(pVertexDecl);
	dxDevice->SetIndices(pIndexBuffer);
	dxDevice->SetStreamSource( 0, pVertexBuffer, 0, sizeof(VFORMAT) );
	dxDevice->DrawIndexedPrimitive(D3DPT_TRIANGLELIST, 0, 0, (UINT)faces.size()*3, 0, (UINT)faces.size());
}

Also, when rendering the .X files I loaded with D3DXLoadMeshFromX:

for( DWORD i=0; i<dwNumMaterials; i++ )
{
	dxDevice->SetMaterial( &pMeshMaterials );
	dxDevice->SetTexture( 0, pMeshTextures );
	pMesh->DrawSubset( i ); //Direct3D9: (ERROR) :Vertex stride in stream 0 is less than in the declaration
}

This problem occurs before any issues with device being lost. Any idea where to look?
Advertisement
The vertex declaration probably doesn't match the stride you pass to SetStreamSource.
I was just about to reply and say I found a problem in my vertex declaration. So I now have the Mesh::Render working properly.

However I am still having the same problem with the mesh that I load using D3DXLoadMeshFromX

Since I do not manage a vertex declaration for that...I don't know how to set it!

I am basically just using example code

HRESULT ShapeNode::Load(const char *filename)	{		LPD3DXBUFFER pD3DXMtrlBuffer;		// Load the mesh from the specified file		if( FAILED( D3DXLoadMeshFromX( filename, D3DXMESH_MANAGED, 			dxDevice, NULL, 			&pD3DXMtrlBuffer, NULL, &dwNumMaterials, 			&pMesh ) ) )		{			return E_FAIL;		}		// We need to extract the material properties and texture names from the 		// pD3DXMtrlBuffer		D3DXMATERIAL *d3dxMaterials = (D3DXMATERIAL*)pD3DXMtrlBuffer->GetBufferPointer();		pMeshMaterials = new D3DMATERIAL9[dwNumMaterials];		pMeshTextures  = new LPDIRECT3DTEXTURE9[dwNumMaterials];		for( DWORD i=0; i<dwNumMaterials; i++ )		{			// Copy the material			pMeshMaterials = d3dxMaterials.MatD3D;			// Set the ambient color for the material (D3DX does not do this)			pMeshMaterials.Ambient = pMeshMaterials.Diffuse;			// Create the texture			if( FAILED( D3DXCreateTextureFromFile( dxDevice, 				d3dxMaterials.pTextureFilename, 				&pMeshTextures ) ) )			{				pMeshTextures = NULL;			}		}		// Done with the material buffer		SAFE_RELEASE(pD3DXMtrlBuffer);		return S_OK;	}	void ShapeNode::Render()	{		for( DWORD i=0; i<dwNumMaterials; i++ )		{			dxDevice->SetMaterial( &pMeshMaterials );			dxDevice->SetTexture( 0, pMeshTextures );			pMesh->DrawSubset( i ); //Direct3D9: (ERROR) :Vertex stride in stream 0 is less than in the declaration		}	}
I've never loaded or rendered a .X mesh, so I can't tell you exactly what you need to do. What I can say is that pretty much every sample that ships with the SDK loads X files, and renders them... just check what one of the really simple samples does.

This topic is closed to new replies.

Advertisement