Saturday, June 26, 2010

Problems Solved!

This was absolutely horrible stuff. I've said it before, but Pix is an absolutely wonderful tool; the way it lets you drill down into all of the functions that get called, examine their parameters, watch your scene build up on-screen, and so on is so valuable for debugging work.

Anyway, I ran a bad scene through it and fairly quickly noticed that my sky setup and takedown code wasn't getting run. A pop back to Visual C++, examine the conditions under which it does and doesn't get run, set some breakpoints, check when those conditions and values change, and we get to the source quickly enough.

So, the new renderer divides it's functionality in two. There's setup code and actual rendering. The setup code builds a list of callback functions and vertex offsets, then writes the stuff that would be rendered into my vertex buffers. The rendering code then replays through the list drawing stuff. The setup can be reset and the list replayed at any point during the frame when things change radically enough that the previous state is no longer valid; this generally only happens when the vertex size changes or when there are too many vertexes and the buffers would overflow, but it can also be called on-demand if I need to.

So what I was doing was running some setup code in a callback function. Setup code that determined what gets buffered up in terms of vertexes and other callbacks. And because that callback hadn't run yet, the determination was not valid which caused things to go quite spectacular on me.

There's a lesson to be learned, but I'm not going to beat up on myself too much over it; the important thing is that it's now working, and that I also know one other thing to watch out for. I also need to go through those callbacks and pull any other setup code out of them in case anything else blows up in the future.

Phew! Result.

0 comments: