Saturday, 31 May 2014

Bug hunting

Kaduria has 7 known bugs. It's not much, but some bugs can be annoying. This time I was fixing a bug that crashed when you threw more than one item on top of another. At first I thought it was a bug in stacking routine. Stacking sets a number to item's data, making it appear as "7 apples" etc. The good thing about this style is that items take less space, since 120 arrows is just one item.

Of course, the bug was not in that routine. I started to doubt it when the crash happened in the dynamic light map routine. It's checking items with light value, then displaying the light. Dynamic map makes it possible to throw a torch and see the light area in real time.

When the item is added to level there is a check for stacking. If suitable item is found, the original item is destroyed. As you can already guess, the original item handle was still in the item map, from where dynamic lighting is finding the handle... why it was there? I've found out that it's easier to actually change the item map when the item is flying, rather than use "a sprite" to represent the flying item. But the original map has to be restored after the item and the most important part is what happens when the item lands. Fixing the bug required two lines of code: set the item location to landing and update the item map.

The way stacking is done may be wrong, because each item has condition (physical, very exact). So any small damage to the item makes it incompatible with other, similar items. It may be possible that I have to reprogram stacking completely and use individual items which then are only displayed as a stack in the inventory and elsewhere.

No comments:

Post a comment