I’ve been doing a lot of mobile development in Titanium lately. One of my current projects has been heavy on graphics and animations, for which I’m not entirely convinced Titanium is well suited. And while I’ve enjoyed building the app, we’ve entered the final testing and debugging stages, and—of course—everything is breaking.
Titanium debugging—especially on Android—is not a joyous thing. While it is true that you can connect your Android device directly to your workstation, a lot of the errors being reported to me recently are
segfaults. These are errors without a directly traceable callstack, which makes them a pain to debug.
The little bit of information I can get from the errors is that they’re happening around animations, but not in any recognizable pattern. Since I’m not an expert Titanium debugger, I ended up tossing in a an
alert or seven, which really didn’t help much.
After what seemed like hours of tweaks and tests, I was able to narrow down the issue to user input events occurring on views while animations were still in effect. The app is a pattern matching game, so animating views based on user input is rather important.
Try, Try, Try…
Figuring out where the problem originated was just the beginning. Attempts to alleviate the issue by disallowing user input during the animation failed on the Android platform. I can’t readily say why. And given the looming project deadline, I couldn’t research the issue. The immediately obvious solution—removing the event listeners from the view until the animation completes—was a total bust. The
removeEventListener call worked perfectly for iOS, but failed to remove the event listener on Android devices. Subsequent
addEventListener calls would then duplicate the user input functionality.
The final solution was to speed up the animations to such a degree that it would be literally impossible for a user to interact with a view to start the animation, and then interact with the view during said animation. This was by no means ideal, but it allowed the project to be completed.
A Future Solution?
Part of my debugging woes probably stemmed from having to build a rudimentary game engine from scratch. It was no small task. Unfortunately, the game engine from Lanica was still in beta when this project started. The Platino Engine looks promising for game development with Titanium Studio. I’ve downloaded the trail, and am rather excited to check out the bells and whistles: physics, sprites, particles, isometric tiles. Oh my!
Given what I had to work with, I think that app turned out pretty well. Perhaps a later update will allow for a rewrite using a hopefully stable game engine like Platino. In the meantime, have any other developers had better ideas about this type of Titanium debugging?