Disko Forum logo Login  |  Register  |  Lost Password
Re:Sigfault by deleting a dynamic created widget.

Duran
Posts: 37
graphgraph

Sigfault by deleting a dynamic created widget. 6 Years ago  
Dear all,

Continuing with my posts in Questions forums, I've tested what happens when a widget that has been created using 'new' command is removed by calling to 'delete'. That is:

I've modified a test program to create two labels in a vertical box (all three elements created using 'new' commands). At every 5 seconds, the program does:
- if the second label exits, it is destroyed, by calling to 'delete' and only one label should be shown.
- If the second label doesn't exists, a new label is created and added to the vertical box.

I've detected a major problem: a widged A contained in another widget B, when widget A is deleted, it doesn't notified to widget B of this it is no longer valid, and widget B should remove the pointer fo widget A and repaint itself, if it is visible.

I undestand that if a widget is created using new, it could be destroyed by calling 'delete', so disko should provide robustness to programmer.

In a similar way, know that shared pointers in C++ are in vogue, what happens if based on the program (one vbox with two labels, all created using 'new', the vertical box is deleted.

Based on my experience with Gtkmm (and of course, this could be discussed), I propose to add a parameter to 'add' member function of boxes, to indicate if the cointainer of the should manage the live time of the new added widget or not (in this situation the programmer should remove the widget, it it destroys the container). For example:

vbox.add(new Label(window), true);
==> the vertical box will manage the live time of the label

vbox.add(new Label(window), false);
==> the programmer will manage the live time of the label

In Gtkmm, to set the management of live time of a widget to a container, a template member functions was used:

MyContainer : public:: Gtk::VBox
{
void create_widgets() // Called from constructor
{
Gtkmm::Label *label = Gtk::Manage<Gtkmm::Label>(new Gtk::Label());
add(*label);
}
}

Note: what happens if I do something like:

VerticalBox.add(0);


Thanks and Best Regards,
Joaquim Duran
File Attachment:
File Name: main-d490efcb6e7cb6d3d5d5a440bbd0738c.txt
File Size: 1463
 
  The administrator has disabled public write access.
Re:Sigfault by deleting a dynamic created widget.

Stefan
Posts: 91
graph

Re:Sigfault by deleting a dynamic created widget. 6 Years ago  
Hi Joaquim,

We also happend to have the problem with the lifetime of the widgets, and just got accustomed that the container gets control of the memory after an add() occured.

We want to add the shared_ptr in one of our next releases. Your idea of selecting the "lifetime manager" will be discussed next week in the disko team.

kind regards
Stefan
 
  The administrator has disabled public write access.
Powered by FireBoard
get the latest posts directly to your desktop