Showing posts with label debugging. Show all posts
Showing posts with label debugging. Show all posts

13 April 2013

The Debug Dialog

When I was creating the iOS version of King of Dragon Pass, I included some of the same debugging utilities we had in the original game. Unfortunately, I couldn’t remember exactly what we had, and there was no good way to look, because the release version of the game didn’t have them. (And it’s real hard to search an mTropolis project.)

I knew there was a way to trigger a specific scene (critical for running them over and over to test all the possibilities). And a set of commands that do things like get rid of all your food (to test things like starvation advice) or get raided by Trolls.

But I knew there was something more, just not what it was.

Today I happened to run into this code
/*
Returns text about our clan helpful for debugging (shown in the \ dialogette)
*/
char* CPlayerClan::DebugInfo() const
{
gString = "farmerMorale: ";
UString::Append(gString, this->MoraleFarmers());
gString += ", warriorMorale: ";
UString::Append(gString, this->MoraleWarriors());
gString += ", thrallMorale: ";
UString::Append(gString, COSL::GetIntegerVariable(var_thrallMorale));
gString += ", mood: ";
UString::Append(gString, this->Mood());
gString += "\rvictory: ";
UString::Append(gString, COSL::GetIntegerVariable(var_victory));
gString += ", kingship: ";
UString::Append(gString, this->Kingship());
gString += "\r";
UString::Append(gString, fYearsAsType, "year", "years");
gString += " as clan type\r";

return (char *)gString.data();
} // DebugInfo

which was clearly used to display some internal status useful for testing.

This isn’t as important as it was in 1999, but we’re in the process of thoroughly testing a number of new scenes (currently 14, but several more are in progress). So I put this into the current debug dialog. It’s almost like seeing a long-forgotten friend.

15 August 2012

Bugs

Like any large software product, King of Dragon Pass is not perfect. We wish it were, so we track bug reports and try to fix things when we do an update.

When we created the original game, we had a quality assurance team to find bugs. We also relied on beta testers. For the iOS version, we don’t have a paid team, and Apple limits the number of outside testers. So we have to rely on players to do much of the bug finding.

Today, a blog comment read “the game seems to be crashing often.” My first thought was “no, it doesn’t!” The second was “that’s not a very good report.” But then I thought, “what if it is crashing more often than I think it is? If so, I want to fix it!”

I remembered that Apple makes crash logs available to developers. Normally, if an app on your iPhone crashes, a log is saved on the device. When you synchronize, it’s copied to your computer. And if you’ve given the OK, it is also sent to Apple. (I believe only when you synchronize, though I’m not sure of the details.)

This is especially handy because Apple will combine duplicate reports. When I logged into iTunesConnect and checked, the top 3 crashes accounted for 71% of the reports. I grabbed these.

The logs by themselves aren’t very useful. They include a stack trace which shows exactly where the crash occurred, but only in numeric form. They need to be symbolicated — cross-referenced against the symbols (typically method or functions) of your app. For this to work, you need to save the symbols with each build. Luckily, when you make an archive to submit to the App store, the symbol table is saved. Unfortunately, Apple’s development tool Xcode is terrible about symbolicating. In fact, I was only able to symbolicate about half of the logs. Luckily, I could get one log from each of the top three crashes. And they all pointed at a method in my AdviceView. In one of them, the call stack included showQuestDialog, so I started showing advice and opening and closing the Quest dialog. Sure enough, I got the crash. From there it was pretty short work identifying what was going on (it was a message sent to zombie object, one that should have been dead). And easy to fix.

So this story has a happy ending, and one that makes me glad I’m an iOS developer and a lot of the work was done for me. (Bigger software developers often create a similar infrastructure themselves, to capture crashes in the field.)

But the moral of the story is: we can’t fix bugs we don’t know about! The 2.0.5 build has been played since February. Nobody mentioned anything until now. Please let us know about problems! http://a-sharp.com/kodp/bug.html explains how to send a report from the game itself. (This won’t do anything with crashes, but you can email bugz «at» a-sharp.com with the reproduction steps, and we can send back the somewhat picky details of finding the logs on your computer.

25 October 2011

Our Newest Ring Member


One of the features in the latest update (version 2.0.4) is a new advisor. Like many in the game, the art is based on a real person. In this case, it’s one of our beta testers, Liana Kerr.

We’ve been blessed by a number of helpful and perceptive testers, willing to spoil their potential fun by playing a buggy copy of the game. Since they’re all volunteers, I added to the pool of beta testers as the game got closer to release. Even a game as repayable as King of Dragon Pass will eventually become jaded, and I wanted fresh eyes. (I did however take a number of testers who had played the game before, figuring that a gap of 10 years would make a difference. And these players could tell me if it was still true to the spirit of the original.)

Unfortunately, something went wrong with our bug tracking system, and I can’t get exact counts of how many bugs each beta tester sent. But even without exact statistics, I know it’s Liana. Although she was an old hand, she dove in, and played seemingly endless games, trying out different approaches, and sending all sorts of reports.

Her enthusiasm was remarkable for someone who had already played the game a lot. Here in her own words is her introduction to the game:
“Back in 2001, when my boyfriend and I were at college, he gave me King of Dragon Pass for Valentine’s Day. (Reader, I married him.) I would have enjoyed it well enough if it had just been a clan simulation based around cattle management, exploration and battles, but the sheer amount of random events and notifications, the focus on mythology, the gorgeous artwork and exceptional writing kept me playing it for years, until I thought I had quite played it to death. Even then, every so often I’d still have the urge to build up a happy little Peace clan swimming in cattle and trade goods!”
Once the game was released, I began working on VoiceOver support, so that blind players could enjoy the game too. There were a few bug fixes in that build too, so I sent it to my stable of testers (plus some blind players). You can imagine my surprise when Liana decided to try the game using VoiceOver! Not only that, but she continued sending insightful feedback that helped make the game more accessible.

This was so over the top that I wanted to do something special to say thank you. I asked our iOS artist, Jani Lintunen, if he could create one more set of advisor faces, and he graciously agreed. Since this was to be a surprise, Jani had little to work with. (By contrast, when Stefano Gaudiano did associate producer Elise Bowditch and myself, we gave him photos of our parents.) But he nailed it. Liana says, “The picture of her when she’s old looks very much like my mom, but older (and my husband thinks it looks like my mom’s sister). It’s really eerie!”

Many testers helped make this game more fun and less buggy. I was lucky to get their help. And lucky Liana was willing to play yet again. Thanks again, Liana, and maybe some day I can arrange a visit from Cragspider…

26 December 2010

Sweeps

King of Dragon Pass is a big game, and while there’s lots of special purpose code, frequently the same basic idea occurs more than once.

One of the techniques we made extensive use of in 1.0, and I’m using again for 2.0, is the sweep. If you find a bug, you need to be sure it’s not present somewhere else. A global text search can find an awful lot. (Apparently the search tools available today are better than they were 11 years ago, because I’ve found a number of textual issues that slipped through the cracks in the original release.)

We also used a change log — revision control systems tend not to be as visible, and Subversion wasn’t even dreamed of in 1997. So quickly searching (sweeping?) for “sweep” reveals some of what we did in script (OSL) files:
  • news_FF54 found a bug with 0 clan, did sweep on this file for similar predicaments
  • music & qmark sweep
  • Qland -> Dragon Pass
  • exPoint sweep
  • dx sweep
  • testee sweep - add (quester) to test where needed
  • typo sweep
  • +- sweep
  • Music sweep
  • sweep for bob dole-isms in exploration news
  • WhoopBonus/moot sweep
More recently, resolving the bloat issue revealed a problem with cleaning up after some objects. This warranted a sweep, and sure enough, two other screens had a similar issue.

On the flip side, sweeping and finding nothing can give you more confidence that there aren’t hidden bugs.

23 October 2010

Instruments Rocks

This post is a little technical, but hopefully it will give some insight into the process of developing for iOS.

Although an iPod touch has 128 MB of RAM (recall that the original game ran on a Windows machine with 16 MB), memory is still relatively limited. Despite fitting in your pocket, it’s doing a lot more than Windows 95 — tons of multitasking to play your music, talk to the network(s), and if it’s an iPhone, handle calls or SMS while you’re in the game. And while the screen has fewer pixels, the original required only 16 bit color, and iPhone has 24 (plus alpha on the interim textures). And we couldn’t do alpha at all in the original.

iOS watches memory closely, and if an app starts getting too greedy, kills it (after sending several increasingly stern warnings). So it’s important not to use too much. But how can you tell?

I think I tweeted before how much better the development tools are than 11 years ago. Instruments is as good as anything I’ve seen and it’s part of the free Xcode tools.

Once I realized there was an issue, I first used the Leaks instrument to look for memory leaks. There weren’t any. One reason for that is Xcode comes with a great static analyzer, which can look at your source code and identify likely leaks. This is an awesome tool, because you don’t have to exercise every piece of code to find memory problems.

But a leak is defined as memory that’s allocated but can’t be accessed. It’s also possible to have accessible but useless objects, which I term “bloat” to distinguish from a true leak.

The Allocations instrument will show each memory allocation, identifying exactly what it is and where in your code it was created. It was pretty obvious that switching between management screens left the old one around. It was even easier to verify this (and make sure it was fixed) by filtering (all the management screens are implemented as UIViewControllers, so I typed “Controller” into the search field). You can see several system-created controllers, but also that there are currently three instances of the Magic screen. (The MagicController may be less than 1 KB, but it manages a host of other objects, so the impact is more serious than it may appear.)

The screen shot shows Instruments running in the Simulator, but the tools work with a device, too. The Mac-hosted simulator has far more RAM than any device, so you can’t easily use it to test for low memory conditions. But the memory allocations are the same, so I can use it for this task. (The development cycle is much faster with the simulator, since you don’t have to copy builds to a device.)

So once I could see what was going on, it was pretty easy to stop the bloat. It’s hard to know how long it would have taken to find this in the past, but definitely more than a couple hours. The great tools are just one reason I like developing for iOS.

Further Reading
Apple has good documentation, but Bill Bumgartner’s “When is a Leak not a Leak? Using Heapshot Analysis to Find Undesirable Memory Growth” is a great article on tracking down bloat with Instruments.

19 August 2010

Debugging KoDP

When we did the original King of Dragon Pass, internal builds had some arcane keystroke that brought up an ugly dialog that let you type a scene number, or click one of dozens of buttons to set state or trigger raids. This was invaluable both for developers and for testers — who wants to play until you run out of cows, just to make sure the game handles that right?

Causing a Scene
The game is far enough along that this would be useful. Instead of an arcane keystroke, it’s invoked by an arcane gesture.

The new version is actually a little easier to use, because it shows the scene name.

Once we have external testers, I want to add another feature which will also be much easier thanks to ten years of operating system progress: the ability to email the debug logs to accompany bug reports.

Wreaking Chaos
This has already been invaluable in testing the interactivity code mentioned in the last post.