Re: [ROOT] Unable to call methods in GUI constructor!

From: Fons Rademakers (Fons.Rademakers@cern.ch)
Date: Sun Feb 16 2003 - 15:06:14 MET


Hi Christian,.

  this might very well be a 10.1 problem. I have this week no access
to my Mac so I can not verify the behaviour on Mac OS X 10.2. Maybe Damir
can try?

Cheers, Fons.



On Sat, Feb 15, 2003 at 06:33:11PM +0100, cstrato wrote:
> Dear Rooters
> 
> The enclosed macro ".x mygui.C" contains two classes,
> called MyFrame and SubFrame.
> 
> In the constructor of MyFrame I am able to call methods,
> however, in the constructor of SubFrame I am unable to
> call any method. Even calling the simple method "Test(1)"
> (see line 321) causes ROOT to crash with:
> 
> root [7] .x mygui.C
> ---TEST - 1
>   *** Break *** segmentation violation
> Root > Function mygui() busy flag cleared
> Function MyFrame() busy flag cleared
> Function CreateShutterFrames() busy flag cleared
> Function SubFrame() busy flag cleared
> Function Test() busy flag cleared
> 
> Can anybody tell me, why I am not able to call a
> method in the SubFrame constructor??
> 
> Note: Yesterday, I could run a similar macro in root
> for about 50 times without problems, until root finally
> crashed with the error described above. Since then, it
> is no longer possible to call a method from the constructor.
> 
> I am using root 3.05/02 on MacOS X 10.1.2
> 
> Thank you in advance.
> 
> Best regards
> Christian
> _._._._._._._._._._._._._._._._
> C.h.i.s.t.i.a.n S.t.r.a.t.o.w.a
> V.i.e.n.n.a       A.u.s.t.r.i.a
> _._._._._._._._._._._._._._._._

> // Test for constructor
> 
> // Menu commands
> enum EMenuCommands {
>    M_FILE,
>    M_FILE_NEW,
> };
> 
> // Shutter commands
> enum EShutterCommands {
>    S_SHUT1 = 1001,
>    S_SHUT1_A,
>    S_SHUT1_B,
> 
>    S_SHUT2 = 1001,
>    S_SHUT2_A,
>    S_SHUT2_B,
> };
> 
> const char *xpm_names[] = {
>     "Folder.xpm",
>     "Folder.xpm",
>     0
> };
> const char *kShutterName[] = {
>     "Shutter1",
>     "Shutter2",
>     0
> };
> 
> struct ShutterData_t {
>    const char *sPixmap_name;
>    const char *sTip_text;
>    Int_t       sId;
>    TGButton   *sButton;
> };
> 
> ShutterData_t kItems1[] = {
>    { "folder_s.xpm", "xxx", S_SHUT1_A, 0 },
>    { "folder_s.xpm", "xxx", S_SHUT1_B, 0 },
>    { 0,               0,    0,         0 }
> };
> 
> ShutterData_t kItems2[] = {
>    { "folder_s.xpm", "xxx", S_SHUT2_A, 0 },
>    { "folder_s.xpm", "xxx", S_SHUT2_B, 0 },
>    { 0,               0,    0,         0 }
> };
> 
> class MyFrame;
> class SubFrame;
> 
> class MyFrame {
> 
>    RQ_OBJECT("MyFrame")
> 
>    private:
>       TGMainFrame        *fMain;
> 
>    // MenuBar Frame
>       TGPopupMenu        *fMenuFile;
>       TGMenuBar          *fMenuBar;
>       TGHorizontal3DLine *fLineH1;
> 
>    // Shutter Frame
>       TGHorizontalFrame  *fHF1;
>       TGShutter           *fShutter;
>       const TGPicture     *fDefaultPic;
>       SubFrame           *fSubFrame;
> 
>    // Layout hints
>       TGLayoutHints      *fMenuBarLayout;
>       TGLayoutHints      *fMenuBarItemLayout;
>       TGLayoutHints      *fMenuBarHelpLayout;
>       TGLayoutHints      *fLineLayout;
>       TGLayoutHints      *fLayout;
> 
>       TList    *fTrash;
> 
>    public:
>       MyFrame(const TGWindow *window, UInt_t w, UInt_t h);
>       virtual ~MyFrame();
> 
>       void AddShutterItem(const char *name, ShutterData_t data[], Int_t id);
> 
>    // Slots
>       void DoCloseWindow();
>       void DoShutter(Int_t id = -1);
> 
>    private:
>       void CreateMenuBar();
>       void DeleteMenuBar();
>       void CreateShutter();
>       void DeleteShutter();
>       void CreateShutterFrames();
>       void DeleteShutterFrames();
> 
> //      ClassDef(MyFrame,0) //MainFrame
> };
> 
> class SubFrame {
> 
>    RQ_OBJECT("SubFrame")
> 
>    private:
>       MyFrame            *fMyFrame;
>       TGCompositeFrame   *fShutterFrame;
>       TGCompositeFrame    *fFrameA;
>       TGGroupFrame         *fFG1;
> 
>       TList    *fTrash;
> 
>    public:
>       SubFrame() {}
>       SubFrame(TGCompositeFrame *parent, MyFrame *main, UInt_t w, UInt_t h);
>       virtual ~SubFrame();
> 
>       void HandleShutter(Int_t id = -1);
> 
>    private:
>       void Test(Int_t k) {cout << "---TEST - " << k << endl;}
>       void CreateFrameA();
>       void DeleteFrameA();
> 
> //      ClassDef(SubFrame,0) //SubFrame
> };
> 
> 
> //______________________________________________________________________________
> //______________________________________________________________________________
> 
> 
> //ClassImp(MyFrame);
> //ClassImp(SubFrame);
> 
> //______________________________________________________________________________
> MyFrame::MyFrame(const TGWindow *window, UInt_t w, UInt_t h)
> {
>    fTrash = new TList();
> 
>    fMain = new TGMainFrame(window, w, h);
>    fMain->Connect("CloseWindow()", "MyFrame", this, "DoCloseWindow()");
> 
> // Create menus
>    this->CreateMenuBar();
> 
> // Basic frame layout
>    fLayout = new TGLayoutHints(kLHintsTop | kLHintsExpandX | kLHintsExpandY);
>    fHF1 = new TGHorizontalFrame(fMain, 20, 20);
>    fMain->AddFrame(fHF1, fLayout);
> 
> // Create shutter
>    this->CreateShutter();
>    this->CreateShutterFrames();
> 
> // Main settings
>    fMain->SetWindowName("MyGui");
>    fMain->MapSubwindows();
>    fMain->Resize(fMain->GetDefaultSize());
>    fMain->MapWindow();
>    fMain->Move(20, 20);
> }//Constructor
> 
> //______________________________________________________________________________
> MyFrame::~MyFrame()
> {
>    this->DeleteMenuBar();
>    this->DeleteShutterFrames();
>    this->DeleteShutter();
> 
>    delete fHF1; 
>    delete fMain;
> 
>    delete fLayout;
> 
>    fTrash->Delete();
>    delete fTrash;
> }//Destructor
> 
> //______________________________________________________________________________
> void MyFrame::CreateMenuBar()
> {
> // File menu
>    fMenuFile = new TGPopupMenu(gClient->GetRoot());
>    fMenuFile->AddEntry("&New...",  M_FILE_NEW);
> 
> // Create menubar layout hints
>    fMenuBarLayout = new TGLayoutHints(kLHintsTop | kLHintsLeft | kLHintsExpandX, 0, 0, 1, 1);
>    fMenuBarItemLayout = new TGLayoutHints(kLHintsTop | kLHintsLeft, 0, 4, 0, 0);
>    fMenuBarHelpLayout = new TGLayoutHints(kLHintsTop | kLHintsRight);
> 
> // Add menus to MenuBar
>    fMenuBar = new TGMenuBar(fMain, 1, 1, kHorizontalFrame);
>    fMenuBar->AddPopup("&File",        fMenuFile, fMenuBarItemLayout);
> 
>    fMain->AddFrame(fMenuBar, fMenuBarLayout);
> 
> // Line to separate menubar
>    fLineH1 = new TGHorizontal3DLine(fMain);
>    fLineLayout = new TGLayoutHints(kLHintsTop | kLHintsExpandX);
>    fMain->AddFrame(fLineH1, fLineLayout);
>    fLineH1->DrawBorder();
> }//CreateMenuBar
> 
> //______________________________________________________________________________
> void MyFrame::DeleteMenuBar()
> {
>    delete fLineH1; 
>    delete fMenuBar;
>    delete fMenuFile; 
> 
>    delete fMenuBarLayout;
>    delete fMenuBarItemLayout;
>    delete fMenuBarHelpLayout;
>    delete fLineLayout;
> }//DeleteMenuBar
> 
> //______________________________________________________________________________
> void MyFrame::CreateShutter()
> {
>    fDefaultPic = gClient->GetPicture("folder_s.xpm");
>    fShutter = new TGShutter(fHF1, kSunkenFrame | kFixedWidth | kDoubleBorder);
> 
>    this->AddShutterItem(kShutterName[0], kItems1, S_SHUT1);
>    this->AddShutterItem(kShutterName[1], kItems2, S_SHUT2);
> 
>    TGLayoutHints *hint = 0;
>    hint = new TGLayoutHints(kLHintsTop | kLHintsLeft | kLHintsExpandY);
>    fTrash->Add(hint);
>    fHF1->AddFrame(fShutter, hint);
>    fShutter->Resize(100, 400);
> }//CreateShutter
> 
> //______________________________________________________________________________
> void MyFrame::DeleteShutter()
> {
>    delete fShutter;
> }//DeleteShutter
> 
> //______________________________________________________________________________
> void MyFrame::CreateShutterFrames()
> {
>    fSubFrame = new SubFrame(fHF1, this, 0, 0);
> }//CreateShutterFrames
> 
> //______________________________________________________________________________
> void MyFrame::DeleteShutterFrames()
> {
>    delete fSubFrame;
> }//DeleteShutterFrames
> 
> //______________________________________________________________________________
> void MyFrame::AddShutterItem(const char *name, ShutterData_t data[], Int_t id)
> {
>    TGShutterItem    *item;
>    TGCompositeFrame *container;
>    TGButton         *button;
>    const TGPicture  *buttonpic;
>    TGLayoutHints    *hint;
> 
>    hint = new TGLayoutHints(kLHintsTop | kLHintsCenterX, 5, 5, 5, 0);
>    fTrash->Add(hint);
> 
>    item = new TGShutterItem(fShutter, new TGHotString(name), id);
>    fTrash->Add(item);
>    container = (TGCompositeFrame*)item->GetContainer();
> 
>    for (Int_t i=0; data[i].sPixmap_name != 0; i++) {
>       buttonpic = gClient->GetPicture(data[i].sPixmap_name);
>       if (!buttonpic) {
>          printf("Shutter: missing pixmap \"%s\", using default",
>                 data[i].sPixmap_name);
>          buttonpic = fDefaultPic;
>       }//if
> 
>       button = new TGPictureButton(container, buttonpic, data[i].sId);
>       fTrash->Add(button);
>       button->Connect("Clicked()", "MyFrame", this, "DoShutter()");
>       button->SetToolTipText(data[i].sTip_text);
>       data[i].sButton = button;
>       container->AddFrame(button, hint);
>    }//for_i
> 
>    fShutter->AddItem(item);
> }//AddShutterItem
> 
> //______________________________________________________________________________
> void MyFrame::DoCloseWindow()
> {
>    delete this;  //does not exit root
> //   gApplication->Terminate(0);  //exit root, needed for standalone App
> }//DoCloseWindow
> 
> //______________________________________________________________________________
> void MyFrame::DoShutter(Int_t id)
> {
> }//DoShutter
> 
> 
> //______________________________________________________________________________
> //______________________________________________________________________________
> SubFrame::SubFrame(TGCompositeFrame *parent, MyFrame *main, UInt_t w, UInt_t h)
> {
>    fMyFrame = main;
>    fTrash = new TList();
> 
> // Subframe for frame containing different shutter frames
>    TGLayoutHints *hint = 0;
>    hint = new TGLayoutHints(kLHintsTop | kLHintsExpandX | kLHintsExpandY);
>    fTrash->Add(hint);
>    fShutterFrame = new TGCompositeFrame(parent, w, h);
>    parent->AddFrame(fShutterFrame, hint);
> 
> //THIS DOES WORK!!
>    fFrameA = new TGCompositeFrame(fShutterFrame,0,0, kHorizontalFrame);
>    fShutterFrame->AddFrame(fFrameA, hint);
>    fFG1 = new TGGroupFrame(fFrameA, "Group frame for A", kVerticalFrame);
>    fFrameA->AddFrame(fFG1, hint);
> 
> // Create shutter subframes
>    this->Test(1);
> //THIS DOES NOT WORK!!
> //   this->CreateFrameA();
> //   this->Test(2);
> 
> // Show first frame
>    fShutterFrame->ShowFrame(fFrameA);
> }//Constructor
> 
> //______________________________________________________________________________
> SubFrame::~SubFrame()
> {
>    this->DeleteFrameA();
> 
>    fTrash->Delete();
>    delete fTrash;
> 
>    fMyFrame = 0;
> }//Destructor
> 
> //______________________________________________________________________________
> void SubFrame::HandleShutter(Int_t id)
> {
> }//HandleShutter
> 
> //______________________________________________________________________________
> void SubFrame::CreateFrameA()
> {
>    TGLayoutHints *hint1 = 0;
>    hint1 = new TGLayoutHints(kLHintsTop | kLHintsExpandX | kLHintsExpandY);
>    fTrash->Add(hint1);
> 
>    fFrameA = new TGCompositeFrame(fShutterFrame,0,0, kHorizontalFrame);
>    fShutterFrame->AddFrame(fFrameA, hint1);
>    fFG1 = new TGGroupFrame(fFrameA, "Group frame for A", kVerticalFrame);
>    fFrameA->AddFrame(fFG1, hint1);
> 
>    fShutterFrame->HideFrame(fFrameA);
> }//CreateFrameA
> 
> //______________________________________________________________________________
> void SubFrame::DeleteFrameA()
> {
>    delete fFG1; delete fFrameA;
> }//DeleteFrameA
> 
> 
> //______________________________________________________________________________
> void mygui()
> {
>    new MyFrame(gClient->GetRoot(), 400, 220);
> }


-- 
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 7679480



This archive was generated by hypermail 2b29 : Thu Jan 01 2004 - 17:50:09 MET