Jump to content
  • Advertisement
  • entries
  • comments
  • views

Cautionary Tales in Debugging

Sign in to follow this  


Always name your variables well - even if you're just writing temporary hack code to try something out.

I spent several hours today (well, most of it was yesterday) tracking down a bug in some experimental vector math code of mine. It's the kind of stuff that's sensitive to real-time behavior, so you can't step through it in a debugger without ruining the numbers - scrubbing through a few MB of logs is the only way to find out what's going on.

For instance, at one point during this process, I had a couple of angle variables and was freely copying values between them. Thanks to some poor naming on my part, I was feeding radians into a segment of the calculation that expected degrees. (I later discovered that, thanks to someone else's poor namings, the part that was in degrees was wrong, and the whole darn thing should have been in radians to begin with.)

It was downhill from there.

I'll spare the long tale of woe and boredom (actually, it wasn't that bad - most of the time was spent 30 miles away at a poker game) and get to the punch line. I had two vectors, vref and vcam. They were to be adjusted via a series of rotations, producing the results av and avcam.

My final output was relying on the raw vectors, vref and vcam. The net result was bogus data getting fed down the pipeline; the visible result of that was chaotic behavior that was nearly impossible to trace to specific stimuli. In other words, the most pernicious type of bug. The type that makes a 30 minute prototyping task chew up 5 hours.

Sign in to follow this  


Recommended Comments

Gah. I'd take the other method and just spend another 30 minutes rewriting it until it worked. :P

Share this comment

Link to comment
I'd take the other other method where I dont touch the damn code for 30 days, and 'have a small break'!

Share this comment

Link to comment
That's not a naming error, that's a type error, or at least it should be. Unfortunately, C++ and most other languages don't have any built-in support for units like this, although it's trivial to hack together a class per unit to avoid misinterpretation.

Share this comment

Link to comment

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
  • Advertisement

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

GameDev.net is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!