Menu

#3 Glow::NumToplevelWindows bad values

open-fixed
None
5
2014-08-20
2001-11-13
John Nagle
No

Glow::NumToplevelWindows returns an incorrect count of the number of top level windows.

The bug is in glow.cpp:

void Glow::_RemoveWindow(
int windowNum)
{
// Find entry in registry
_WindowRegistryIterator iter = _windowRegistry.find(windowNum);
if (iter != _windowRegistry.end())
{
// Update numToplevelWindows
GlowSubwindow* wind = (*iter).second;
if (dynamic_cast<GlowWindow*>(wind) != 0)
{
--_numToplevelWindows;
}
...

The dynamic cast to GlowWindow* always fails, because _RemoveWindow
is called from the destructor of GlowSubwindow. GlowWindow is derived
from GlowSubwindow, so the destructor for GlowWindow is
called before the destructor for GlowSubwindow.
At the point the destructor for GlowSubwindow is called, the object
is no longer a GlowWindow. Thus, the dynamic cast always fails.

Checking instead whether the window has a parent might work.

[Compiled with VC++ 6.0 SP 5]

Discussion

  • John Nagle

    John Nagle - 2001-11-13

    Logged In: YES
    user_id=5571

    I fixed this by checking for

    !wind->Parent()

    instead of the dynamic cast. I also added an assert at exit to check that the number of top-level windows
    was 0, and it is. But I haven't tried modal GLOW windows, or running this under X-windows, so it needs
    more testing.

     
  • Daniel Azuma

    Daniel Azuma - 2002-06-18
    • assigned_to: nobody --> dazuma
     
  • Daniel Azuma

    Daniel Azuma - 2002-06-18

    Logged In: YES
    user_id=18901

    John's fix approved and checked in on the trunk and the
    1.0.x branch.

     
  • Daniel Azuma

    Daniel Azuma - 2002-06-18
    • status: open --> open-fixed
     

Log in to post a comment.