# XNA: “TextureCoordinate0” missing, but I'm not using textures

I'm trying to create a voxel game using XNA, but I'm getting a somewhat bizarre error when calling DrawIndexedPrimitives():

InvalidOperationException was unhandled
The current vertex declaration does not include all the elements required by the
current vertex shader. TextureCoordinate0 is missing.


Which makes some sense, as it's true my vertex data structure (VertexPositionColorNormal as shown in this Riemers tutorial) does not contain texture data.

However, the effect shouldn't require texture data - I made it a point to set drawingEngine.TextureEnabled = false; in my graphics setup method. So why is this exception being thrown? And what can I do about it?

For some context, here's my draw method:

public void Draw(SpriteBatch drawer)
{
drawingEngine.View = player.createViewMatrix();

Vector3 direction = player.getDirection();

for (int x = 0; x < mapSize; x++)
{
for (int z = 0; z < mapSize; z++)
{
Chunk drawee = map.get(new IntVector3(x, mapCenter, z));
if (drawee == null)
continue;
if(drawee.isTransparent())
continue;
#region chunkdrawer

DynamicVertexBuffer vertexBuffer = drawee.getVertexBuffer();
int numVertices = drawee.getNumVertices();
DynamicIndexBuffer indexBuffer = drawee.getIndexBuffer();
int numIndices = drawee.getNumIndices();

graphics.SetVertexBuffer(vertexBuffer);
graphics.Indices = indexBuffer;

foreach (EffectPass p in drawingEngine.CurrentTechnique.Passes)  //Not sure I entirely understand this
{
graphics.DrawIndexedPrimitives(PrimitiveType.TriangleList, 0, 0, numVertices, 0, numIndices / 3);
}
#endregion chunkdrawer
}
}
drawer.End();
drawer.Begin();
}


And here is the graphics setup method:

void graphicsNonsense()
{
drawingEngine = new BasicEffect(graphics);

drawingEngine.World = world;
drawingEngine.Projection = projection;

drawingEngine.TextureEnabled = false;
drawingEngine.VertexColorEnabled = true;

drawingEngine.EnableDefaultLighting();
drawingEngine.SpecularColor= new Vector3(0, 0, 0);
}

• Try to enable VertexColors in the drawingEngine structure like you disabled textures, see if it helps. – János Turánszki Nov 30 '14 at 8:55
• Yeah, I did that, no change :( – littlebeast Nov 30 '14 at 10:00
• It's probably worth noting that I also tried putting those two statements into the foreach effectpass loop, which also yielded no change. – littlebeast Nov 30 '14 at 10:49

Try calling p.Apply() in your drawing code to set the effect correctly on the GPU before drawing.

foreach (EffectPass p in drawingEngine.CurrentTechnique.Passes)
{
p.Apply(); // this will set the effect
graphics.DrawIndexedPrimitives(PrimitiveType.TriangleList, 0, 0, numVertices, 0, numIndices / 3);
}