Game Design, Programming and running a one-man games business…

Anatomy of a gratuitous bug

I think I’ve fixed a bug in the gratuitous space battles campaign game. I’ll know ‘officially’ soon, but it fixed it on my machine :D Here’s what was involved.

A player complained of a random crash bug at the end of some campaign battles. I could not ever reproduce it, and back-and-forth emails began. Eventually, this awesome customer provided me with exact steps to reproduce, and all their save game data to let me replicate it. First run through and….. nothing. It was fine. Roughly every third run-through, in release mode it crashed…

Step 1! Hurrah! it actually crashes for me. This is 50% of the battle because then I *KNOW* that it is the games fault, and not the gamers system, or software. This is good, although frustrating news.

Step 2! It crashes in debug mode. This is another 25% of the battle because I can actually see what data is corrupt. As it turned out, the ‘firstfleet’ pointer in the code that assigns captured ships to the players winning fleet is clearly trashed. How did this happen?

Step 3… debugging. It transpires that the firstfleet pointer is accessed multiple times before this point, and after being initialised, confirming that it *must* have been valid, and becomes invalid between initialisation and access when adding captured ships to the fleet. This means we  can step through and watch what happens, if I break on initialisation..

Step 4 discovery! Stepping through the code confirms my suspicions. Once the battle ends, the code updates all the players fleets and removes ships that died in battle. Then, other code innocently picks the first of the players fleets in the battle, and initialises a dialog box listing the enemy captured ships that will be assigned to the fleet. Later…. *drum roll* it deletes any fleets that are now empty. Can you see the bug yet?

Step 5: fix! Changing the code that naievely picked the ‘first fleet’ to pick the first player fleet that still has some intact ships ensures that the later deletion of an empty fleet, and invalidation of the pointer is harmless, because the captured ships are now getting added to a surviving fleet. Bug probably fixed, pending the player confirming that a new exe fixes it.

Why did I not spot this bug six months ago? Well here is what has to happen.

  1. The player has to fight a battle with multiple fleets at once (common).
  2. He has to win (fairly common)
  3. The ai has to lose by the right margin to leave some captured ships (fairly rare).
  4. The winning player has to have enough ships removed from the *first* fleet in the list to have that fleet entirely deleted, despite winning overall. (pretty darned rare).

Simply put, This didn’t happen to me once in testing. It hasn’t happened to many players either, as I understand it. And if it has happened to you… I may have good news :D

Gratuitous Space Patch 1.57

Just made patch 1.57 live. it will auto update over the next 24 hours, and make it to steam once a day or so has passed without incident. It’s mostly stuff to support the parasites expansion.

version 1.57
1) New Feature: Support for longer race descriptions.
2) New Feature: Modding support for custom bullets textures.
3) Support for return-to-sender capability on missiles.
4) Support for more than one plasma missile in flight at any one time, per launcher (if configured for that module)
5) Support for flak guns (bullet modules with area-of-effect damage).

More work of the gratuitous parasites

I did a little bit of work this morning on the parasites, the GSB race I’m working on in my spare time (ha!).

I added two new weapons today. One is just a tweak, it’s  a plasma launcher that fires lots of small plasma torpedoes rather than big ones. The plasma torp is balanced as a weapon that isn’t colossally effective, but it is able to damage both shields and armor. It now has a rapid-firing version (parasites only).

I also added a ‘return-to-sender’ version of the guidance scrambler beam. This doesn’t scramble enemy missiles, but reverses them, so that they fly back and destroy the person who launched them. often there won’t be fuel for that, and I’m considering making it also reset their fuel. The beam is a one shot deal, you can’t reverse a reversed-missile.

All the ship hulls are done, it’s just balancing and code now. here is another screenshot of some cruisers:

I’m also working on gameplay and GUI for Gratutious Tank Battles. The GTB UI mockups look incredible, it’s just a looooong slow process of translating them into working code.

Gratuitous Parasites

The next expansion pack for GSB is taking a while, because I’m so busym, but I did get time to at least finalise ONE of the ships in the new race. This is the Parasite Anthozoa Cruiser

Some of todays achievements!

An edited list of stuff I checked off my list today:

  1. Added the ‘100,000 copies sold’ text to the GSB website.
  2. Implemented the new menu/GUI (non-battle) music for GTB.
  3. Carried out a major rethink and rebalancing of the way weapons work in GTB, with some research, and a lot of code changes.
  4. Changed the way the AI accrues supplies in ‘classic’ TD mode. It now gets them over time just like the player.
  5. Implemented new green grassy textures.
  6. Checked the performance of the new AI code.
  7. Changed all weapons so there are more shots, doing less damage per shot, and longer durations for beam lasers.
  8. Added a new, obvious drop-unit effect to show when the AI has placed a new turret.
  9. Made fog of war an option, at least for me when I’m debugging, and probably for singleplayer too.
  10. Fixed bug where the AI kept trying to put new troops on top of existing ones in a trench.
  11. Fixed bug where the AI never replaced destroyed turrets.
  12. Managed to not get sidetracked into finishing off the ships for the GSB ‘parasites’ expansion :D

Not bad for the first day back after holidays.  I also riskily (some might say) threw some of my savings at the stock market buying shares in renishaw, a company I’ve bought and sold before, whose profits just jumped, and yet the share price dived 10%. That looked like a buying opportunity to my eyes. Fun fun…