« Earth and Moon Viewer Updated | Main | Reading List: They Thought They Were Free »

Saturday, September 16, 2006

Your Sky, Home Planet, and Sky Screen Saver Updated

There seems to be a rule that the more times you copy a piece of code into different programs, the more probable it is that you'll eventually find a bug which requires you to update all of them. That's what happened with the star map projection algorithm I've been using in Home Planet ever since 1992, which eventually made its way into the Sky Screen Saver and the Web planetarium Your Sky. When plotting items like the boundaries of constellations, which are logically “straight lines” between celestial co-ordinates expressed in right ascension and declination, the charts created by these programs may have to render them as curves depending on the map projection being used and their location in the sky. The code which does this used a recursive “divide and conquer” algorithm which continued to divide the line into sub-segments until the midpoint was within a specified tolerance of the correct location or a fixed limit was reached. Unfortunately, the logic didn't consider the case where, due to round-off, the computed midpoint fell outside the chart, which caused the clipper to return meaningless co-ordinates, resulting in the plotting process looping effectively forever. The fix is quite literally a one-liner, but of course it has to be applied to each of the five programs (since Your Sky contains separate programs for Sky, Telescope, and Horizon views). The corrected version of Your Sky is now in production, and versions 3.3a of Home Planet and 3.1b of Sky Screen Saver which incorporate the fix are available for downloading from their respective pages.

The update to Home Planet also includes two additional fixes. Microsoft can change the name of their C compiler as many times as they like, gussy up the integrated development environment with toolbars, floating panels, bouncing buttons, and flashing mouse-sticking hobble-help all they like, but it's like putting lipstick on a monkey—it's still a monkey, and it's still Monkey C. It was the experience to trying to get Home Planet working in the face of egregious and inexcusable code generation and optimisation flaws in what was then called Microsoft Visual C++ which first brought home to me just how shoddy Microsoft's standards of quality were and how low a priority they seemed to put on delivering products to their customers which got the right answers. (For example, there was a bug in the C library tan function which caused it to return results with the incorrect sign for one quarter of its entire domain. This went unfixed for an entire release cycle of the compiler and library.) Many things have changed since 1992, but not the quality of Microsoft development tools. The “Visual Studio .NET” C compiler contains a hideous bug in code generation for expressions in which multiple subexpressions use the comma operator to evaluate one item and then return another. This caused the specification of latitude and longitude for a user-defined observing site, code which has been working without problems for fourteen years on earlier Microsoft compilers, to break in a way which would be humorous if not so pathetic: the expression is evaluated as if the variables in the subexpressions were written in reverse order.

An additional, unrelated fix corrects a problem which caused the Sky window to fail to be redrawn after being resized when an animation was in progress but paused. This bug has been present since the first release of Home Planet but was not apparent until logic was added in version 3.3 to eliminate unnecessary updates of the Sky window.

Posted at September 16, 2006 20:44