[ROOT] Re: TGClient::WaitFor(TGWindow*) seg fault?

From: Fons Rademakers (Fons.Rademakers@cern.ch)
Date: Mon Jul 30 2001 - 13:51:18 MEST


Hi David,

  the problem is due to the fact that when after the slot methods are executed
(which do a "delete this"). The button objects are still referenced internally
in the signal handling code. However these buttons have just been deleted.
A fix is the following:

in AcceptInput() do:

void TStringInputDialog::AcceptInput()
{
  cerr << "AcceptInput()" << endl;

  if (fReturnValue) {
    const char* value = fTextEntry->GetBuffer()->GetString();
    *fReturnValue = new char[strlen(value) + 1];
    strcpy(*fReturnValue, value);
  }

  //delete this;
  fDialog->SendCloseMessage();
}

and add a new DoCancel method that should be bound to the Cancel button
instead of binding CloseWindow() directly to the Cancel button:

void TStringInputDialog::DoCancel()
{
   fDialog->SendCloseMessage();
}

To see other examples look at $ROOTSYS/tutorials/guitest.C and search for
SendCloseMessage().


Cheers, Fons.



> Hi,
>    In trying to create a simple input dialog, I've encountered a problem 
> I don't understand. If the user presses return in the dialog's input 
> field or clicks the dialog box, everything works as expected. But if the 
> user clicks either of the two buttons (OK and cancel), after the dialog 
> disappears, and it's dtor is called, ROOT complains of a segmentation 
> violation.
>    My code is based on the dialogs.C tutorial. The main difference is 
> that I'm using the signal/slot mechanism in place of ProcessMessage (and 
> interpreted code).
>    Since the code is rather long, I've posted it in 
> http://www.public.iastate.edu/~dfaden/root/TStringInputDialog.cc  and
> http://www.public.iastate.edu/~dfaden/root/TStringInputDialog.hh
>    I'm running this code under ROOT 3.01/05 9 June 2001 under RedHat 6.1 
> i386.
>    I've stuck a few cerrs into the code to try to see what's going on. 
> Here's the output from first closing a dialog by hitting return in the 
> dialog's input field, and then closing a dialog by clicking the OK button:
> 
> root [0] char* storage;
> root [1] new TStringInputDialog("My dialog","Give me input",&storage);
> AcceptInput()
> Destructor #1
>            #2
>            #3
> root [2] storage                                                      
> (char* 0x93e8470)"soup"
> root [3] new TStringInputDialog("My dialog","Give me input",&storage);
> AcceptInput()
> Destructor #1
>            #2
>            #3
> 
>  *** Break *** segmentation violation
> 
> 
> 
>    I suspect that the problem is mine but am mystified as to why closing 
> the dialog through its input field or dialog box works fine, while 
> closing it through the buttons leads to a seg fault. Any insight would be 
> much appreciated.
>    Thank you.
> 
> David
-- 
Org:    CERN, European Laboratory for Particle Physics.
Mail:   1211 Geneve 23, Switzerland
E-Mail: Fons.Rademakers@cern.ch              Phone: +41 22 7679248
WWW:    http://root.cern.ch/~rdm/            Fax:   +41 22 7677910



This archive was generated by hypermail 2b29 : Tue Jan 01 2002 - 17:50:53 MET