Sign in to follow this  
ValMan

Custom batching: wrong materials applied

Recommended Posts

Hello,

I wrote my own batching system to replace D3DXSprite because I wanted more flexibility. Recently I started getting this problem - when I drop my in game console and start typing, some of the triangles rendered later in a batch than the console text suddenly start flashing with the wrong texture.

It's as if, for a duration of one frame, when a new pair of triangles gets added to the render batch for typed character, something in the batch processing code goes wrong and one of the renderables gets the texture from a previous or next renderable in sequence.

I realize there is nothing you can do that would be much better than what I can do, since I wrote the code, but the reason I am asking is because when I do a PIX run and record every single frame from start to finish.... The flashing doesn't show up!

How can this be? If I can see some triangles with the wrong texture applied for a split second that means at least one frame must have those triangles textured with the wrong texture. Yet as I looked though every single frame in Pix capture, all the rendering was spot-on perfect and all the D3D calls were perfect. What's worse, this problem only happens in Release mode! So I can't even step through anything to debug and try to see what goes on.

Has anyone had an experience such as this one? Can you recommend some other debugging method to catch what's happening? I just finished writing some debugging code that dumps the contents of render queue each time it gets submitted to DirectX, looked carefully through the thousands of entries for every triangle and every batch, and everything looks perfect as well! I really don't know what to do any more.

Share this post


Link to post
Share on other sites
[EDIT]

Updating for anyone who might later get the same problem. It appears the cause of this error is two-fold.

The reason the problem was happening only in Debug mode is because vertex buffers get cleared to 0s by the runtime for validation purposes - so if you try to draw something and pass a cleared vertex buffer you get no output. So, no output in PiX also.

The reason the weird flashing and wrong texturing was happening is because I was calling DrawIndexedPrimitive and passing it wrong data to render (which only occurs in Release mode because otherwise that "wrong data" gets cleared and produces no output). Specifically when I passed BaseVertexIndex value to DrawIndexedPrimitive I had no idea that this value actually gets added to every index in the index buffer. Perhaps the docs weren't clear or perhaps I am a bad reader. In any case, I was passing BaseVertexIndex thinking it's just a simple offset where it starts reading even though in reality this value gets added to every index.

As of this time I haven't gotten it to work yet, still digging through details, but I am happy that I found the cause of this error. It gave me headaches for 4 months.

[Edited by - ValMan on September 30, 2010 1:08:02 PM]

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this