2005-10-26

 

Debugging plus

Yesterday I had a cool debugging session while working on my HDR demo. One of postprocessing filters produced weird results and I went off to investigate that. The usual tricks: debugging in Visual Studio to make sure right sample offsets are generated; D3D debug runtime, D3DX debug, reference rasterizer, firing up NVPerfHud and doing frame analysis, doing full capture with PIX and inspecting device state, etc.

Nothing helped.

Then I noticed that in the pixel shader, I wrote
sample = tex2D( s0, uv + vSmpOffsets[i] )
instead of
sample += tex2D( s0, uv + vSmpOffsets[i] )
Aaargh. So much for a plus sign.

How to deal with such bugs? Why some bugs are trivial to find, and some are hard? Why sometimes (often?) the time required to find the bug does not correlate with bug's "trickiness"? Why sometimes I can find a tricky bug in big unknown codebase in a couple of minutes; yet spend two hours on the plus sign in my own small code?

I've got no answers to the above.

By the way: PIX is a great tool, but D3D guys should really polish the UI :)

Comments
i know exactly what you mean. it's always the stupidest trivial errors that cause the bugs that are most difficult to track down.

the other day i spent a couple hours tracking down a rendering bug that turned out to be an error in the operator== for an object in a hash table.

it was something like this:
return foo == rhs.foo && bar == rhs.bar && something == something;

compiler didn't warn and i looked over it a couple times without even spotting it!
 
Yeah, I spent few hours on a bug of similar origin yesterday. Somehow when You know what is supposed to be written, You get an "optical illusion" that it actually is there. Reading the code as if You've never seen it before helps (at least it did for me).
 
Yvl: yeah, someone other taking a look at the code really helps. Too bad that I did this at home, and neither my wife nor my daughter did provide any useful suggestions ;)
 
Well, my favorite "hard to find" bug is :
for(i = 0; i < N; i++);

that semicolon becomes invisible to my eyes
 
Post a Comment

<< Home