Some useful tips on debugging your code from roel at devmaster.net. This is in response to a question about collision detection in C#, but the same techniques apply to a wide range of situations in game programming.

roel writes: “Use your debugger to find out what happens …. If the problem occurs arbitrarily, this is usually my approach:

  • make your code work deterministically: fixed timesteps, random number generators with fixed seeds;
  • add a frame / iteration counter;
  • add code that detects your problem “player is one pixel above the ground” and then outputs that counter;
  • run your program and remember the value of the counter;
  • add a breakpoint when that counter is reached so that your debugger kicks in in advance of the frame/iteration where the problem occurs;
  • restart your program and wait until the breakpoint is reached;
  • step through it and see what went wrong and fix it.”

Leave a Reply