Wednesday, January 19, 2011

AS3 class name collision - a story of one bug

Recently I spent almost a day fighting with a mysterious Flash error.

Here is the situation. The system is structured in the following way: One SWF (a wrapper) loads other SWFs (let's call them “modules”). One of the modules, in turn, loads another SWF, which we will call “content”. The wrapper is being developed by one programmer, the content – by another and I am working on the module (a typical setup for a virtual world project).

The wrapper is tied to the server in many ways, so I prefer to test locally only the module and the content (besides, the interaction between the wrapper and the module is minimal, and was already tested).

So, I launched the module locally, and the system run fine. The content is loaded, the module cast it to the required interface and called certain methods on the content – everything is perfect. Then I uploaded the module and the game to the server, launched the entire system , and the flash player reported an exception. I checked the source and quickly realized that the exception happened because the module could not cast the loaded object to the required interface.

My first thought was that the SWF for some reason cannot be loaded from the server. I've added all possible error handlers, and found nothing. The content was loaded in the following way:

_loader = new Loader();
_loader.contentLoaderInfo.addEventListener(Event.COMPLETE, onLoadComplete, false, 0, true);
_loader.contentLoaderInfo.addEventListener(IOErrorEvent.IO_ERROR, onErrorLoading, false, 0, true);
_loader.contentLoaderInfo.addEventListener(IOErrorEvent.NETWORK_ERROR, onErrorLoading, false, 0, true);
_loader.contentLoaderInfo.addEventListener(IOErrorEvent.VERIFY_ERROR, onErrorLoading, false, 0, true);
_loader.contentLoaderInfo.addEventListener(SecurityErrorEvent.SECURITY_ERROR, onSecurityErrorLoading, false, 0, true);
_loader.load(new URLRequest(fileLocation));

Here is what happened in the onLoadComplete method:
log.debug("loader info content type:"+_loader.contentLoaderInfo.contentType);
log.debug("loader info URL:"+_loader.contentLoaderInfo.url);
log.debug("loader content:"+_loader.content);
myContent = _loader.content as MyContentInterface;
The onErrorLoading method was never called; the only method executed was onLoadComplete. When running module locally, I was getting the following output in the log:
10:33:00:453 [DEBUG] loader info content type:application/x-shockwave-flash
10:33:00:453 [DEBUG] loader info URL:file:///C|/Projects/[... some correct path here ...]/Main.swf
10:33:00:453 [DEBUG] loader content:[object Main]
And here is what I was getting on the server:
12:01:03:375 [DEBUG] loader info content type:application/x-shockwave-flash
12:01:03:375 [DEBUG] loader info URL:[... correct URL...]
12:01:03:375 [DEBUG] loader content:instance43942.instance43943
It is obvious that the difference is in the loader content: in one case it is an object, and in the other case it contains some strange instances.

At this point I got stuck. I tortured the developer of the content SWF, asked him to try different compile modes (with/without network support etc...), checked file versions and paths on the server, checked security settings – all without any success or any clue.

After many painful hours, all of a sudden I got an insight. I run and checked the source code for the wrapper and for the content SWFs. Turned out that the developers of both wrapper and content SWFs called their main classes Main, and put them in the default package. Of course, the content SWF was loading fine, but its Main class could not be loaded because of the name collision. When the content developer moved his Main class into the proper package the problem was solved and the whole system worked like a charm.

The most curious thing here is that the Flash player did not complain about the name collision in any way – it just silently ignored the problem.

Hopefully my story will help someone and save their time.

Thursday, February 25, 2010

How to prepare a code sample

In some companies asking the job candidates to provide code samples before the interview became a standard part of the hiring process. Here are some guidelines which will help you to avoid common mistakes, make a good impression with your code, and, as a result, get the interview.

1.Pick the right code.

Select the code which is as relevant as possible both to the technology and to the industry. Of course, exact match is not always possible, but try to avoid obvious mismatches. For example, for a position of a Java developer, Java code will be, naturally, the best. C++ or AS3 might do; Perl or Haskell will be poor choices – quite possible that the engineer who will review your code will not know these languages and will be unable to adequately evaluate it.

Do not send too much. For me, 1-2 files is generally enough to get the idea.

Be careful about sending entire projects. First, usually projects are much bigger than what I really have time to evaluate. Second, I might be tempted to build the project and run it – therefore, you have to make sure that the code not only looks good, but also runs good.

Send only the code that was written by yourself. Even if the other person's code is a part of the project, don't send it (here is another good reason not to send a full project).

Do not send trivial or auto-generated code. A class which consists only of data members and getters/setters is not very interesting to review.

2.Prepare the code

If there is a well-known style guide for your language, make sure your code follows it. It always makes a good impression and shows you as a professional, who knows and respects the standards and conventions of the industry.

Also make sure that:
  • Your code has enough comments, and that the comments follow the format recommended for your language (for example, in Java the comments should follow the JavaDoc rules). The comments should include one comment per code unit (module, class etc), and one comment per function (method etc.). Reviewer should be able to easily understand the purpose of the code and get some idea how the code is supposed to work.
  • There is no obvious debugging and development leftovers. Remove all commented out lines, TODO markers, unused variables, debug printing etc.
  • The variables and functions have meaningful names.
  • The code is formatted so it is easy to read.

If your code has a comment with a copyright statement of one of your previous companies, think again, whether you can send it. If you still want to send it, remove the copyright statement.

Remove all references to a sensitive information. Don't worry if it will make the code unusable, or even prevent it from compiling – just make sure you explained it in the code and in the comments.

3.Prepare yourself.

If your code will be good enough to get you an interview, remember, that your code most definitely will be a part of the conversation, so:
  • Make sure you understand and can explain each and every word of the code.
  • If your code uses some design patterns, be ready to discuss them.
  • Be ready to explain how the code works.

Monday, April 06, 2009

Unusual games at GDC 2009

Two very interesting events at GDC were IGF (Independent Games Festival) and experimental gameplay workshop. I immensely enjoyed people presenting new creative ideas, prototypes and finished games, and I wrote down the names of the games that caught my eye into my little black notebook. So today I want to share the list with you, my dear readers. But I have to start with three disclaimers.

1. This by no means is a comprehensive list of all interesting or unusual games presented at GDC. It is not even a complete list of the games I liked! And I want to say, that I admire everybody who had imagination to invent new games, willpower to make them, and guts to present them at GDC.
2. Some of the games are not completed yet, and exist only as prototypes.
3. Some of the things I am going to mention are not games. They are "game-like creations". Be prepared – here be some weird stuff.

Complete Games.

  • "Dyson". According to the game’s site the game is "an ambient real-time strategy with abstract visuals". The game is about controlling self-replicationg machines to take over asteroids. The game looks strange and interesting!

  • "Musaic Box". Created by a Russian team, this game won an "Excellence in design" award at IGF! Congratulations, guys! It was cool to hear "Spasibo" from the stage! The game is being sold now by Big Fish Games.

  • "Closure". This is an in-browser flash game, built around an idea, that if you can’t see something (because it’s too dark), then it doesn’t exist. Try it!

  • "Rom Check Fail". I’ve seen this hilarious game some time ago, but I will happily share it again. If you’ve ever played some old arcade classics, such as "Pac-Man" or "Frogger", then you must play this delightful parody!

  • "Storyteller" and "I wish I were the Moon". These are not games – more like a study in alternative storytelling. They are short and very unusual. Give them a try – they are in-browser.

Ideas, prototypes etc.

  • "Blueberry Garden". Beautiful and strange graphics make this game a piece of art. I didn’t get an opportunity to play it myself, but I watched other people playing, and they seem to like it.

  • "Feist" seems to be some sort of platformer – but I just love the art!

  • "Machinarium". From the creators of "Samorost" and "Samorost 2". Again, look at the art!

  • "The Unfinished Swan". This is a first – person exploration game, which takes place in a totally white world. The player runs with a (probably) paintball gun, which shoots balls of black paint, so the player can see some parts of the world. It’s hard to explain – check out the trailer.

  • "Miegakure". Unfortunately, the game’s site has only one paragraph about it, but I just had to mention it – a game which happens in a 4D world, which can be somehow manipulated in 3D…

  • "Achron". The site defines it as "meta-time strategy game", which means RTS with time travel enabled. By “enabled” I mean all interesting possibilities which arise from a capability to change future by changing the past. Weird – but I do want to play it!

Thursday, April 02, 2009


As I said in my previous post, OnLive attracted quite some attention at GDC 2009. Here are some more details about this new service. The details come from my conversation with one of OnLive representatives – unfortunately, I don't remember his name.

The general idea of the service can be stated as "Games on demand" (similar to movies on demand). The user gets a client for the OnLive service, which can be either software client in form of a computer program, or hardware client in form of a “microconsole” - a small box which is connected to broadband Internet and to TV via HDMI connection. Then the user is connected to OnLive server and can play any game he or she wants. The came runs on the OnLive servers, and the image, sound and control commands are transmitted between the client and the service over the Internet. So, essentially, your TV (or computer) becomes just a remote terminal for OnLive servers.

I've heard already some talks about OnLive being the tomorrow of the gaming and about the imminent death of consoles as we know them now (and of PC gaming as well). From my point of view, these claims are a quite exaggerated (to say the least). First, the service currently works with maximal resolution of 1280 x 720, that is in 720p mode. From what I understand, this is a limit imposed by the bandwidth (actually, I think it is a miracle they provide stable image at this resolution!). As you can see, the resolution is even worse than 1080p, provided by Xbox and PS3 , to say nothing about decent gaming PCs. Another fact is lag. At the expo the demo run from the server located approximately 50 miles away from the convention center, and the feeling of the games was OK – though even with server that close I felt some “softness” of the control – not a lag, just some unusual feeling. In real life the distance to server will be significantly larger, and this effect will, probably become more noticeable.

So, I think hardcore gamers will not switch completely to this service. As for more casual gamers – this, of course, will depend heavily on OnLive pricing system. From what the OnLive representative told me, they are still unsure about the model, but, most probably, they will charge the users some subscription fee, and then charge some amount per game. Until we know more about the prices, it will be hard to tell whether it will be less expensive to use the service, or, maybe, in the long run the purchase of a console will be more financially reasonable.

Another interesting thing about OnLive is that it makes easy to continue playing your game when you are traveling – as soon as there is a good broadband connection, the player can access the games from anywhere (if there is a server not too far, of course).

For developers OnLive might be interesting because of several features:

  • Stable target platform – knowing target hardware will make development much easier;

  • Direct distribution channel, with possibility to dynamically adjust pricing and get real-time business data;

  • Reduced piracy and cheats.

Porting the games to OnLive platform is not transparent – developers will have to use special SDK (available for free) to implement, for example, save/load and multiplayer features in the new environment. As of now, there are no plans to support any sort of community or indie game development for OnLive.

By the way, as for now the multiplayer happens only within OnLive network – though in future it might change.

To sum it up: I don't think that OnLive will "kill gaming as we know it", but I do think that the service is extremely interesting and promising.

Tuesday, March 31, 2009

GDC 2009 Summary

Yes, I know, this short summary of GDC 2009 got a bit delayed. But, I think, better late than never (it seems more and more to become my permanent motto).

In short – it was cool. But for me it was slightly less cool than the previous one, maybe because I’ve started seeing some repetitions in GDC patterns. But still, it was worth going - tons of inspiration and some pretty interesting talks and new connections.

These are some most important (from my point of view, of course) points from GDC 2009:

  • iPhone. The same way last year everybody was infatuated with Facebook, this year game developers got a new darling: iPhone. Tens of sessions were dedicated to iPhone development, and iPhone marketing, and iPhone business (One session was titled “Why did iPhone Changed Everything”). There are two reasons people are so excited about it: first, selling apps on iPhone is easy, manageable and understandable process; second, iPhone is, no doubt, an incredibly sexy device. By the way, it seemed like every second GDC attendee was a proud iPhone owner.

  • Social games. Not Facebook-specific anymore, the topic of combining social networks with games is still incredibly hot. The variety of games is wider – from virtual worlds to massively single-player games to advergames that created their own social network… And, of course, everyone is dreaming about marrying social games to iPhone.

  • Onlive. This new service offers to use your TV as a dumb terminal for playing top-of-the-line games on a remote server. It attracted much attention on GDC; I talked with some guys from this company and will post more details tomorrow.

  • Recession. Many production-related sessions were discussing how to survive it, and there was some feeling of uncertainty in the air.

These are the highlights. In the next couple of days I will post more details about Onlive, as well as name some of the games that caught my eye.

Friday, February 27, 2009 Redirection and Spam

It happened so that I use premium redirection service for my emails. (When I started using it it wasn't premium, and it wasn't either. It was Altavista – does anyone remember this word? - giving out “permanent personal email addresses for life”.) The service works slowly, but it used to work more or less stable – and I am too lazy to change my primary email address in gazillion places.

Recently, however, I started getting complaints from my correspondents. They told me that my mailbox bounces their emails. I also started to notice that I am missing some emails. I tried reaching customer service – they told me that everything is all right, yes, everything's fine, and I couldn't reproduce the effect.

Yesterday, when my wife told me that she got her mails bounced, I got really angry. I asked her for the error, she showed me the bounced letter, and then I understood what happened. I logged on to my account – which I usually never do, because, as I said, I am using them only as redirector – and discovered that they turned on spam protection.

I definitely didn't ask for it, and I don't remember them telling me about it (though I could have overlooked the notice). Which is worse, the setting were totally absurd – caught spam was stored in a “Junk e-mail” folder on the server, so I had no clue that some messages were sorted out. (They could have tag them as spam, or, at least, send me once a day a reminder that such and such messages were put into Junk folder – their system knows that I use it only as redirector!).

I turned their spam protection off, and I hope it will fix my problems. So, just a word of advice – if you are using premium redirector, go to the server and check the settings – it might save you from some unpleasant surprises later.

Wednesday, February 25, 2009

In search of a ticketing system

Using ticketing systems to organize project workflow became almost my second nature, and now I am looking for a good system to use with my personal projects. Here is what I need:

  • The system should be simple enough to be usable in a small-scale environment.

  • It should provide all core ticketing features. Tickets should have reasonable set of data fields: type (defect/feature/enhancement etc), status, due date, etc. The system should provide me with capability to assign tickets, to append notes and comments to tickets, to attach files to tickets. It should also provide reasonable number of canned reports (my tickets/all open/ due today etc).

  • The system should also have some basic notion of projects, and should be multi-user (I mean that personal to-do lists will not do).

  • The system should be able to notify me with email about all relevant events (ticket assigned to me, edited, closed etc.)

  • The system should be easy to use; preferably with an option to turn off unneeded features.

  • It should be installable on a server with no command line access.

  • ... And, yes, it should be free.

So far I played with two systems that my hosting provider could install automatically: phprojekt and dotproject. I didn't like both of them. PHProjekt was just too huge for me, with no way to turn unneeded modules off (I do not need timecards, chat or helpdesk features, thank you). Dotproject was somewhat better – at least it allowed me to hide all unused modules, and provided more help on its configuration screens. But then I discovered that creating new tickets (“tasks”) was possible only from the project screen, and I decided that this is too inconvenient to be useful.

From my other projects I have experience with Jira (love it, but it's not free), RT (not again, thank you!), Trac (pretty cool, and free – but, alas, requires command line access to install), and FogBugz (also not free). So, now I am at loss – is there any software at all which fits my needs?