Monday, August 10, 2009

The Most Frustrating Bug I Ever Tracked Down

In PreviousLifeTheLast, I was responsible for developing a wide range of marketing software with a financial bent (student loans, repayments, electronic applications with calculators, etc.)  For one client, the calculation side was much more prominent than usual.  But we had to do it in MacroMedia Director because it had to be pretty.  And, because we could use a Designer rather than a Real ProgrammerTM.

The designer we chose was really good.  He even became a pretty good programmer.  But after he was gone, we had to do the final cleanup before distribution.  Then, The Bug was found!  I don't even remember who found it -- the client, our testers, our tech review?  In any case, everything ground to a halt so we could get it fixed.

What was it? Sometimes, when clicking to leave an entry field or to go to another field, nothing would happen or the cursor would go to the wrong field.  It took us hours to even come close to isolating the behavioral coditions, let alone diagnose the problem.  Eventually, I put in debugging code to dump coordinates (because single-stepping wouldn't work since the problem code and the debugger both used the mouse!)

Finally, we saw it.  In essence, the code was doing the following (in pseudo-code, I don't remember Director syntax anymore):



if (onMouseClick()) {
where = getMousePosition() ;
[ do additional processing ]
}


Looks like a pretty foolproof way to detect a mouse click and find out where on the screen it occurred, right?

Obviously, FAIL!

One would think that an event like a mouse click would trap some pertinent information such as time, right/left/middle, position, etc., to then be used by the calling application.  But, nooooooo .......

The program gets the information that a click has occurred and then has to ask for the current mouse position.  So Director returns the information of the position at the time of requesting the position (or, worse yet, once Director gets done with whatever overhead and interrupts it may be processing.)  So, if the button is clicked while the mouse is moving, the program gets the position of where the mouse/cursor has moved by the time the program gets around to asking for it.

Of course, if the position isn't anywhere close to where the click happened (even a few pixels may make a difference between a button hit/non-hit), it was anybody's guess what might happen.

I don't remember how we fixed the problem.  But I do remember that a system should not be designed with that kind of object/event sloppiness.

No comments:

Post a Comment

The Out Campaign: Scarlet Letter of Atheism
free debate