Inside SWT

Wednesday, July 26, 2006

"I just click around all day ..."

Fixing bug 125656 was a real challenge. You can go read the bug report, but the summary is that a certain combination of hover help windows and clicking caused the operating system (MacOS X 10.4) to lose track of top level shells, making them dead to mouse clicks. This problem was particularly hard to find because it was intermittent. Attempts to construct a simple case outside of Eclipse failed.

So how did we fix it? First of all, we investigate the obvious. Is the shell somehow disabled? Are the mouse events going somewhere else? Is there a mouse grab stuck? Is the shell somehow disposed but still drawing? Then we discovered that FindWindow, the MacOS X carbon call that is used to locate a window given a point on the screen, couldn't find our window. Calls to IsValidWindowPtr showed that the window was still alive. What could possibly be the problem?

To find out, we wrote a method that traversed the operating system window list and soon noticed that there were shells in SWT data structures that were not in the list. We called the method after every event was dispatched and traced all the operating system calls to find out when the bad thing happened. We did all this in Java, not C, which is one of the great things about SWT. No custom C code.

I almost forgot. When a problem is intermittent, you can't ever really know for sure that it's fixed. You have to rely on statistics. So Silenio spent two days on and off, narrowing down the mouse clicks until he could get the problem to happen within 5 minutes. During that time, I asked him what he was doing and he said, "I just click around all day ..."



Post a Comment

<< Home