Page 1 of 1

updateWindowContainingMouse bug

Posted: Tue Aug 17, 2010 14:15
by ianstangoe
Hi CE,

I've discovered a bug in this function which fatally crashes, this is with the latest stable branch code.

Basically when I hide all my menu windows getCommonAncestor() is passed a NULL pointer for d_wndWithMouse here:

Code: Select all

    // do the 'area' version of the events
    Window* root = getCommonAncestor(oldWindow, d_wndWithMouse);

    if (oldWindow)
        notifyMouseTransition(root, oldWindow, &Window::onMouseLeavesArea, ma);

    if (d_wndWithMouse)
        notifyMouseTransition(root, d_wndWithMouse, &Window::onMouseEntersArea, ma);


getCommonAncestor() doesn't check for this and neither does the above code, I'm not sure what the desired behaviour should be in this case, it would seem logical to still notify the system that the mouse has left a window... :?

I made the following changes which appear to work fine for me although you'll know more about the notification process :)

Code: Select all

//----------------------------------------------------------------------------//
Window* System::getCommonAncestor(Window* w1, Window* w2)
{
   if (!w1 || !w2)
   {
      if (!w1 && !w2)   
         return 0;

      if (w1)         
         return w1;

      return w2;
   }

    if (w1 == w2)
        return w1;

    // make sure w1 is always further up
    if (w1 && w1->isAncestor(w2))
        return w2;

    while (w1)
    {
        if (w2->isAncestor(w1))
            break;

        w1 = w1->getParent();
    }

    return w1;
}

updateWindowContainingMouse():

Code: Select all

    // do the 'area' version of the events
    Window* root = getCommonAncestor(oldWindow, d_wndWithMouse);

    if (root && oldWindow)
        notifyMouseTransition(root, oldWindow, &Window::onMouseLeavesArea, ma);

    if (root && d_wndWithMouse)
        notifyMouseTransition(root, d_wndWithMouse, &Window::onMouseEntersArea, ma);


HTH.

Ian.

Re: updateWindowContainingMouse bug

Posted: Tue Aug 17, 2010 18:45
by CrazyEddie
Thanks for catching this one - I'll get a fix in for it tomorrow :D

CE.