Development log
by Ivan Kravarščan
It has been over a year since I got the report of division by zero bug from the Play Store. Thanks to a kind player who shared a save two weeks ago I finally fixed it.
Sometimes when a player ends a turn the game would crash and the saved game could not be played any more (it would reliably crash when ending the turn). The report I’d receive from Play Store would indicate that research points invested in a technology field was not a number. “NaN” (not a number) is a special floating point “number” value and it’s usually a result of division by zero. The provided save file would also crash when opening the research screen.
Debugging revealed that the human player’s total research progress in a certain field was NaN because one of the colonies contributed NaN research points due to having no population. A colony with zero population would have zero industry potential, a value that would be used as a denominator when calculating the ratio between effective active and passive research.
Well, from the above the obvious fix is to not divide by zero. If industry potential is zero, skip calculating ratio and simply report zero research output for the colony. That’s a fix that was delivered in the v3.29 update. But that’s not the end of the story.
Why was the colony population zero? Also the number of factories is NaN. Oh and all that happened at a size 3 star that has just built a colony ship with 3 more in orbit, and no further events. This rules out bombardment or invasion glitch. NaN factories are probably a red herring, just a consequence of zero industry potential. Colony ships are the smoking gun here and I bet they managed to scoop more population then they were supposed to. The player had no colony ship capacity upgrades and no industry to build more than one per turn so that last ship could only take away 1 unit of population. I’ll need to check more thoroughly how it managed to break through the limit and depopulate the colony.
That is, one day when I get enough free time. It’s getting scarce again and I’d like to bundle it with one more thing. Recently there was a review that complained about micromanagement because troop ships are one off projects. Well there were more points in the review but this one is relevant now. In order for troop ships to be a repeatable construction project I’ll need to revise construction queue logic (again) to make sure they don’t scoop up more troops than what is available. I did make automated tests for various construction queue scenarios but apparently this slipped through somehow. Honestly I do cheat a bit in those tests by creating mock maps with one or two stars with size of 1000 so they could build things in a single turn without test failing if I change how techs work. I’ll need to make some way to specifically test building stuff at small stars.
tags: