Hello,

just stumbled across a problem with fltk2's Group::replace(). Other than
e.g. Group::add() it does not disconnect the new widget from its 
original parent. This leaves a dangling pointer in the original parent
if the added widget happens to have a parent when it is inserted via 
replace. Something like the patch below fixes that.

Regards,
Johannes


diff -r 08b98fdd06fd src/Group.cxx
--- a/src/Group.cxx     Sun Nov 04 21:13:14 2007 +0100
+++ b/src/Group.cxx     Thu Dec 06 10:40:18 2007 +0100
@@ -230,6 +230,14 @@ void Group::remove_all()
 /*! Remove the indexed widget and insert the passed widget in it's place. */
 void Group::replace(int index, Widget& o) {
   if (index >= children_) {add(o); return;}
+  if (o.parent()) {
+    int n = o.parent()->find(o);
+    if (o.parent() == this) {
+      if (index > n) index--;
+      if (index == n) return;
+    }
+    o.parent()->remove(n);
+  }
   o.parent(this);
   array_[index]->parent(0);
   array_[index] = &o;

_______________________________________________
fltk mailing list
[email protected]
http://lists.easysw.com/mailman/listinfo/fltk

Reply via email to