Game Development Reference
In-Depth Information
A good place to start this check is in your main loop and at the top and bottom of
major components like your resource cache, draw code, AI, or sound manager. Place
the check at the top and bottom to ensure that you can pinpoint a body of code that
caused the corruption. If a check succeeds before a body of code and fails after it, you
can begin to drill down into the system, placing more checks, until you nail the exact
source of the problem. Here
'
s an example:
void BigBuggySubsystem()
{
BuggyObject crasher;
CheckForTheBug(
Enter BigBuggySubSystem.
);
DoSomething();
CheckForTheBug(
Calling DoSomethingElse
);
DoSomethingElse();
CheckForTheBug(
Calling CorruptEverything
);
CorruptEverything();
CheckForTheBug(
Leave BigBuggySubSystem
);
}
In this example, CheckForTheBug() is a bit of code that will detect the corruption,
and the other function calls are subsystems of the BigBuggySubsystem .It ' s a good
idea to put a text string in your checking code so that it
'
s quick and easy to identify
the corruption location, even if the caller
'
s stack is trashed.
'
'
Since there
t
fret if your checking function finds a corruption on entry. You can target your search
inside the destructors of any C++ objects used inside the previous scope. If the
destructor for the BuggyObject code was wreaking some havoc, it won
s plenty of C++ code that runs as a result of exiting a local scope, don
'
t be caught
by your last call to your checking function. You wouldn
'
t notice it until some other
function called your checking code.
Draw Debug Information
This might seem incredibly obvious, but since I forget it all the time myself, I figure it
deserves mentioning. If you are having trouble with graphics- or physics-related bugs,
it can be invaluable to draw additional information on your screen such as wire-
frames, direction vectors, or coordinate axes. This is especially true for 3D games,
but any game can find visual debug helpers useful. Here are a few ideas:
n Hot areas: If you are having trouble with user interface code, you can draw
rectangles around your controls and change their color when they go active.
You
'
ll be able to see why one control is being activated when you didn
'
t
expect it.
 
 
Search WWH ::




Custom Search