Not everything goes as planned, but I like to fix bugs fast. Especially bad ones.
The WP7 version of geoDefense has a bad bug in it which causes some people to lose all their scores. I call this losing their "progress". Although it won't erase any Xbox LIVE Achievements earned (after you leave trial mode anyway).
So what was the bug and why has it taken me this long to find it?
This is going to sound like an excuse, and it is: I'm on vacation. I'm in Bangkok with my lovely girlfriend Emma. And up until a couple days ago we were on the island of Ko Lanta. The internet there is really dicey.
Now I should have had the capability to debug this with me, but I didn't. My Windows rig is not a laptop, and I had not boot-camped my Backbook Air. Boo on me. I wanted to do it, but I waited to the last minute and got the dreaded problem where "some files cannot be moved" during the repartition. It was one day before I had to fly off to WWDC (Apple's big developer conference) and, immediately from there to Thailand. So I had to skip it.
So no Windows and not even my WP7 in hand, I had to get on this bug because my total time away from my rig was going to be a whole month!
The best I could do was screenshare remote into my machine at home and boot up VisualStudio that way. Fortunately I had a friend watching my house, so she was able to reboot my machine into the right mode (and keep it that way, as its stormy back in St. Louis and we lost power multiple times through this process).
Screensharing is slow in the best of circumstances. My connecting was far from the best of circumstances. Lets just say it was painful! Really painful! So slow a single action (like clicking on something) could take 3 or more seconds to respond.
Ultimately I was not able to see what the issue was. I had to fall back on the Microsoft Support Group engineers. I hooked them up with my code-base and a fine programmer by the name of Dennis Cheng found it. His proposed solution wasn't WP7-compatible, so I had to take a different route on the solution.
Despite better internet in Bangkok, it was still painful to try and reproduce this bug in the emulator back in St. Louis via screensharing. I had to play it just right to create the circumstances.
How just right?
Well the issue is in the file handeling. Essentially your highscores (and other info) are saved to a file (duh). But the data is in put into a form that is checksummed and other safeguards against tampering. This is the same way it works on the iPhone, and essentially a direct port of that code. And it seems to work, and usually does.
The problem was that when I wrote the file I did it with a filemode of OpenOrCreate. That's the bug. Because when I wrote new data to the file, if the file already existed, I might not end up with what I expected. Essentially it boils down to this... the length of the data I'm writing varies by how much content there is. Generally the file just keeps getting bigger as new highscores are added, and this is never a problem. However if the data being written is smaller than the last time, then the resulting file will still be as long as it was before the save... with the data at the end being garbage.
When I load the data, I get this trailing garbage and the whole block fails the checksum checks and thus it disregards the data as if it had been tampered with.
Worse, because it throws that away, it will continue to be in this "no save" state because the very next game you win will yield yet-smaller amounts of valid data than what you had before. It never will be able to save any further progress that can load properly.
The reason the data can be smaller is because of the way it encodes values. Surface it to say it takes less bytes to store a large score than a small one, or the number of lives lost, etc. So when replaying a level, you can end up creating a win scenario that takes less bytes to represent than the last time, in total. And boom goes the dynamite.
The fix is trivial: Just use file mode of Create and it'll start a fresh new file. Stupid newb mistake. But there it is. Maybe I cut and paste something, an even more newb mistake. Typical, it's always something trivial that causes the biggest issues.
The bug fix is done and submitted to Microsoft. It has to go through their process before it becomes and update, and this does take awhile. The version with the fix will be 1.6.
In the meantime, if you play geoDefense WP7, just don't replay any levels you've already won and the bug won't happen. If it's already happened, uninstall and reinstall the game to clear the state. Once 1.6 update is out and you upgrade, then you can safely go back and replay already won levels to improve your score.
Needless to say, I deserve the lumps on this one. I messed up. It was a really hard bug to reproduce and I thank Microsoft for coming through for all of us here!
Now, I'm off to explore more of Bangkok!