]> git.tdb.fi Git - libs/gltk.git/commitdiff
Avoid generating events during destruction of a widget
authorMikko Rasa <tdb@tdb.fi>
Mon, 28 Feb 2011 15:22:39 +0000 (15:22 +0000)
committerMikko Rasa <tdb@tdb.fi>
Mon, 28 Feb 2011 15:22:39 +0000 (15:22 +0000)
source/widget.cpp

index 17bc4e3c95c96a6aed1f3e5eb14129b6951fdd72..a5a0f2d511801402c611c2a55f61218483b6d67c 100644 (file)
@@ -30,7 +30,11 @@ Widget::Widget():
 Widget::~Widget()
 {
        if(parent)
-               parent->remove(*this);
+       {
+               Container *p = parent;
+               parent = 0;
+               p->remove(*this);
+       }
 }
 
 void Widget::set_position(int x, int y)
@@ -70,6 +74,8 @@ void Widget::set_parent(Container *p)
 {
        if(parent && p)
                throw InvalidState("Widget is already in a Container");
+       else if(p==parent)
+               return;
        parent = p;
 
        on_reparent();