Hacking and Flashlight Bugs

Hey Folks! Another round of bug fixes today. This time involving hardware items.

Yesterday's errant laptop turned out to be due to hacking encounters not using the treasure encounters provide as a reward directly. Instead, it compares the player's items to the reward, and if there is a certain kind of match, the player item is mode-switched. But the comparison object was never cleaned-up, hence the extra laptop in memory after a hacking encounter.

In the process, I also discovered a leak due to items being loaded from a save game. Default items that came with a container get replaced by save game data, and this was only partially covered. Some items, such as hardware, had their own way of doing this, and needed handling, too.

Once the laptop was fixed, I started playtesting. And before too long, I discovered another crash bug. This time, it was flashlights.

Apparently, the ChangeMode() function on items wasn't correctly updating the template's "use count." Each template, from which items are derived, has a counter to keep track of how many items use it. Sort of a manual reference counter like those garbage collectors use.

In the case of ChangeMode, however, it was possible for the mode change to fail (usually due to lack of charges). And if that happened, it would briefly switch to the new mode, then back to the old one. And the way it was coded, the old and new template items could both end up destroyed even though the item finished reverting to normal and using one of them (the old one).

So I updated ChangeMode() to account for this increment/decrement in use count, and all seems well now. It was tricky to find, but easy to solve. Sound familiar? :)

Anyway, yay more stability! Also, yay weekend! It was a pretty productive week, and I'm feeling a bit better about things. So I think I'll enjoy the weekend this time. See y'all Monday!