Problems with deleting self

Started by
11 comments, last by xgecko 22 years, 3 months ago
Thanx Kylotan,

till now I did it with posting events to parents and than processing it in the main loop, but now I want to assign to class (CButton) a C++ event (with libsigc) and call it some way :-), but the way I used before is not usable.

Gecko
Advertisement
quote:Original post by xgecko
Hi Oluseyi!

Your code is nice, but it doesn''t resolve the problem. When I insert delete closeButton; in Close(), it crashes :-(

That''s because Close() is being called from a method of the closeButton. What you should actually do is pass a code of some sort to the DialogBox, allow the CallbackFn to terminate and then in a polled loop of the DialogBox (like an Update() method) respond to the code. For example, DialogBoxClose() could be defined so:
// assume bClose is a boolean member variable of DialogBoxvoid DialogBox::Close(){  bClose = true;} 

This will allow all closeButton methods to properly terminate. We now define a DialogBox::Update() procedure:
void DialogBox::Update(){  ...  if(bClose)  {    ...    delete closeButton;    // do everything else necessary to terminate self  }  ...} 

When does Update() get called? Every iteration of your GUI loop - or whenever it is you update the interface/process its messages.

[ GDNet Start Here | GDNet FAQ | MS RTFM | STL | Google ]
Thanks to Kylotan for the idea!
quote:Original post by Oluseyi
Original post by xgecko
Hi Oluseyi!

Your code is nice, but it doesn''t resolve the problem. When I insert delete closeButton; in Close(), it crashes :-(

That''s because Close() is being called from a method of the closeButton. What you should actually do is pass a code of some sort to the DialogBox, allow the CallbackFn to terminate and then in a polled loop of the DialogBox (like an Update() method) respond to the code. For example, DialogBoxClose() could be defined so:
// assume bClose is a boolean member variable of DialogBoxvoid DialogBox::Close(){  bClose = true;}  

This will allow all closeButton methods to properly terminate. We now define a DialogBox::Update() procedure:
void DialogBox::Update(){  …  if(bClose)  {    …    delete closeButton;    // do everything else necessary to terminate self  }  …}  

When does Update() get called? Every iteration of your GUI loop - or whenever it is you update the interface/process its messages.

[ GDNet Start Here | GDNet FAQ | MS RTFM | STL | Google ]
Thanks to Kylotan for the idea!

This is the way I did first, but I saw in gtk–(gtkmm) that it can be done another way :-)

Gecko

This topic is closed to new replies.

Advertisement