Friday, April 8, 2011

Debugging Is An Art

Most of the time, debugging is an art. It takes a careful balance of knowledge, hard-won experience, compiler tools, investigative skills, and loads of patience. But sometimes there comes a point when even these things have their limits and you throw your hands in the air in frustration trying to figure out what is going wrong.

Case in point: the strange texture bugs I was finding when I tested my engine on a Vista laptop.

Every other feature seemed to be working fine on the laptop, but every time I used a texture, the results were unpredictable. Often times, when rendering a tile map and some terrain features, the same texture would be used everywhere even though the tile map called for a variety of textures to be used...especially when rendering mountains.

Then, when testing some animation features, the textures on the animated model would look okay at first, but when I pressed a key (and another model came onto the screen), the texture on the original model swapped places with the new model that was being rendered.

Ugh.

Then I created a tile map with an array of textures just to test those functions.

The entire map was rendered with the exact same texture.

Can you say, hello brick wall? What was strange was that the issue was only occuring on the Vista laptop, and was not occuring on the XP box or the Windows 2000 I tested the engine on.

Somewhere, in the back of my mind, I kept wondering if it was a graphics driver issue.

I started eliminating possibilities. Was there some unitialized variable somewhere that was holding unpredictable values? Nope. Was the texture loading function failing? After lots of investigative work, the answer appeared to be no.

Then, I spotted a type/casting issue. Surely that must be it, I thought. Fixed the bug. Recompiled and tried again.

No dice.

At this point, things were getting discouraging. To add to the issues, the frame rates on the Vista machine were down by 10-15 fps compared to the XP machine. I know it is a laptop with a low-end processor, but this was ridiculous.

So I checked out some forums. I looked into the OpenGL on Vista issues. I prayed about it. Ugh...I was ready to just give up and live with it.

Then, I checked on the graphics drivers issue. According to the Device Manager's "Update Driver" feature it said I had the most current version of the driver installed.

I didn't buy it.

I went to the manufacturer's website and checked on the drivers that were available. And wouldn't you know it, there was a driver out there that had an update date of 2007 (vs. 2006, which was pre-installed on the machine itself).

At this point I was so used to hitting brick walls with these bugs that I didn't hold out hope. I was preparing a "Plan B". And C. And D. And E...

I installed the new drivers, ready to hit the rollback button if necessary.

And then I tried the engine again.

In one swoop, a whole class of bugs was wiped out. Every. Single. One of them.

The texturing issues went away. Completely. The frame rates shot up 10-15 fps, and in some cases it was faster than my XP machine. Wow what a relief! Now I can really, truly, start focusing on game design.

Moral: check your drivers!

Monday, April 4, 2011

Water, Water Everywhere

Today's screenshot, while rather uneventful looking, actually represents a significant step forward for the engine.


It represents weeks of work...and the final promotion of the water mesh concept into the map tool (and subsequently rendered by the engine). In other words, I can now add water meshes/features to my tile maps, similar to how terrain features (mountains, hills, etc.) can be added to a tile map. Then, when the map is imported into the engine, it will be rendered as a water feature, just like other terrain features.

Additionally, I have also been testing the engine on a Vista machine, as well as a Windows 2000 machine. There are a few minor bugs on each system to work out, but they are not showstoppers. At this point, the engine is officially "feature complete" and I'll be enlisting some other users soon to get rid of as many bugs as possible before moving ahead with games building.

Next up: the game design phase. :-)