views:

57

answers:

1

The following line will error sometimes in my .NET XNA program.

VertexBuffer v = new VertexBuffer(GraphicsDevice, typeof(VertexPositionColorTexture), 4, BufferUsage.None);

The exception that is thrown is InvalidOperationException, and it tells me that:

"The current vertex declaration does not include all the elements
 required by the current vertex shader."

I'm using BasicEffect as my shader. Now, I do change the formats in the vertex buffers I output, but they're outputted right away. I'm not binding multiple buffers at once. They simply get outputted with the primitive functions right away. For my various formats (3 i think), Some don't have textures (VertexPositionColor), some dont have colors (VertexPositionTexture), etc. I also adjust TexturesEnabled, VertexColorEnabled, etc as I go along. I also call Apply on each of the EffectPass's (there's only one pass; since the count is 1)

effect.CurrentTechnique.Passes.First<EffectPass>().Apply();

That line is done before the first one given.

Right now it's erroring at a spot where I'm getting ready to draw a TriangleStrip sprite to the screen. In this case, I'm using VertexColoring, TextureEnabled, Texture is set to the one I want to output (debugging this value shows that its loaded fine). LightingEnabled is false.

Let me also note that this is for a Windows Phone 7 project.

A: 

Fixed it.

The exception thrown wasn't actually caused from what I was doing in this actual render call, but rather the prior. In the previous render call, I was rendering something else with VertexColorEnabled set to true, when it should of been false.

For some reason it didn't crop up till that point, which made it difficult to understand.

Kyle