User login

The Nasty WP7 geoDefense "Progress Lost" Bug

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 Tom Matthews 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 handling. Essentially your highscores (and other info) are saved to a file (duh). But the data is input 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!

David

Comments

its the 30th......

Hi, I cant wait... but I also cant play until its fixed :)

So it has been more than a week since this post and i still am unable to see any updates.. I have unistalled and installed and all I get is version 1.3.

Any updates on this? did MS approve the 1.6 version?

 

Don't sweat it...

Hey David, have fun in Thailand.  Don't worry about the game.  It's a game the core playability is working 100%.  

I've been to Thailand 4 times and you should be enjoying it. It is too amazing to be thinking about this.  We will all still be here playing your game.  We will also buy your next ones when they make it to WP7, just like I have all of them on the iPhone.  :-)

-Joe

 

agree.. but do send a quick note :)

Yep, its still one of the best games on WP7..

but it would be nice to know when the update is available - after winning so many medium levels without losing a single life and then getting all this progress erased.. i am naturally afraid to play until its fixed :)

thanks a lot.

v1.5

Finally got an update today, but only to v1.5.  Having hoped that the issue with the progress would be resolved, it appears in this version at least, that it's not.

Here's to hoping v1.6 is quick to follow.

bug fixed???

I installed the 1.5 update, played a few games and poof, all progress gone, same a 1.4. Perhaps a fresh install instead of an update is required?

Never Mind! :)

I reinstalled the game and it appears to save scores fine now - I finally was able to complete the "Hard Owned" achievement.  Thanks!

V1.6

Hi David.

Any news on the 1.6 update? Still hasn't filtered through to marketplace from what I can see. Has anyone else managed to pick up the 1.6 update yet?

No worries on the bug, gives me an excuse to play through again.

A balance issue for you to mull over for your next project though: I realised that for many difficult levels (e.g. The Hat), it's pretty easy to win simply by ALWAYS building laser towers. Never upgrade until you've saturated the screen, but every time you have sufficient funds, build a new laser tower. Once saturated, upgrade with any spare cash you have. That gives you a massive amount of firepower.

If the upgrade weapon power scales differently (i.e. each upgrade makes the tower substantially more powerful) then it becomes much harder to win using mass-low-level towers and would make the build order a lot harder to figure out. At least, I think that's how it'd work : )

Have a nice hol.

V1.6 arrived

Thanks for the explaination of the bug, it had affected me about a month ago but I wasn't too concerned.

V1.6 just arrived  so I'm looking forward to starting from scratch improving on my lost scores.

Awesome game!

GeoDefense Swarm

Hello,
Do anyone know if a PC ver. will be release.

I have heard a bit about WP7

I have heard a bit about WP7 version of geoDefense. Searching information on the same for a long time but still unable to get enough info on the same. Or whether its a trial version. Also heard that it works on the iPhone too. can any one help me out by giving some info. online gambling

You should follow me on twitter here!