Displaying a context menu via hotkey crashes AIR

 

I love hotkeys and I try to build them into all of my apps. They greatly improve the desktop app experience, especially for the anti-mouse crowd. I recently thought of a handy way of using a hotkey—display a context menu upon pressing the spacebar with an item selected. This feature would be so sweet… if it worked.

I quickly typed up the implementation and tried it. Expecting to see a context menu, I was dumbfounded to see ADL crash without a single RTE stack trace. Here’s an example of the code that causes the crash every time:

At first, I thought it might be an ADL issue, so I compiled the AIR file, installed it, and the insanity continued. Instead of crashing instantly as the app did running on ADL, it first displayed this alert:

contextmenuhotkeybug

Let me known, I’m running the most recent build of AIR. Upon clicking ‘OK’, the app quits. I can run the app all day and a soon as I trigger the context menu to display, this alert appears. I checked the Console and found this:

I also added the full crash reports in the Gist. I’m not sure what it all means, but I filed the bug with Adobe and can only hope it’s fixed sooner than later—this feature would be too cool.

Flash Player says n * 0.01 != n / 100

 

[Update] – Thanks to Wendel and everyone else on Twitter who pointed out why I should have gone to school for programming. This isn’t a bug, just “an artifact of float point operations”.

- - -

It’s no secret I’m an performance freak. I get excited whenever I learn of a new way to save a few milliseconds here or there. A few months ago, I learned that multiplication is slightly faster than division. Since then, I’ve been using multiplication over division when possible. Last night, when implementing alternate unit types in Dwarf, I experienced a strange behavior. As I resized a ruler, the size would randomly jump from two decimal points to 16—for example, 0.95 would appear as 0.9500000000000001.

At first, I just accepted it, but after a while, I decided to conduct an experiment. I tried using division instead of multiplication—surprisingly, this results in 0.95 appearing as 0.95. I then took it a step further and looped through a range of values:

Running from 0 to 500, checking each number for differences in multiplication vs division results in 62 instances where the bug occurs. From the test, I can conclude the following:

– The results do not vary from test to test. (ex: 35 * 0.01 = 0.35000000000000003 every time)

– The additional decimal points vary between 15 and 17 digits in length, with the last number ranging from 1 to 5

– The numbers affected are based on the divisor.

The results of the loop seemed to have a loose pattern, so I plugged them into the Google Charts API. The visuals are interesting, but don’t reveal an obvious pattern:

Next steps are to submit the bug to the mothership and hope for a fix!