Root gui causes a segmentation violation

Hi. I’m making a gui for a code. I’m using root libraries and for a test i’ve used a tutorial code. When i run the code it returns :

[ul]*** Break *** segmentation violation

===========================================================
There was a crash.
This is the entire stack trace of all threads:

#0 0x0000003b9aeac61e in waitpid () from /lib64/libc.so.6
#1 0x0000003b9ae3e609 in do_system () from /lib64/libc.so.6
#2 0x00007fd838297248 in TUnixSystem::StackTrace() () from /home/Federico/root/lib/libCore.so
#3 0x00007fd8382960c3 in TUnixSystem::DispatchSignals(ESignals) () from /home/Federico/root/lib/libCore.so
#4
#5 0x00007fd838bfd1a0 in TGClient::GetRoot() const () from /home/Federico/root/lib/libGui.so
#6 0x000000000040227a in main ()
=========================*** Break *** segmentation violation

===========================================================
There was a crash.
This is the entire stack trace of all threads:

#0 0x0000003b9aeac61e in waitpid () from /lib64/libc.so.6
#1 0x0000003b9ae3e609 in do_system () from /lib64/libc.so.6
#2 0x00007fd838297248 in TUnixSystem::StackTrace() () from /home/Federico/root/lib/libCore.so
#3 0x00007fd8382960c3 in TUnixSystem::DispatchSignals(ESignals) () from /home/Federico/root/lib/libCore.so
#4
#5 0x00007fd838bfd1a0 in TGClient::GetRoot() const () from /home/Federico/root/lib/libGui.so
#6 0x000000000040227a in main ()

The lines below might hint at the cause of the crash.
If they do not help you then please submit a bug repoi’m using scientific linux 6rt at
root.cern.ch/bugs. Please post the ENTIRE stack trace
from above as an attachment in addition to anything else
that might help us fixing this issue.

#5 0x00007fd838bfd1a0 in TGClient::GetRoot() const () from /home/Federico/root/lib/libGui.so
#6 0x000000000040227a in main ()

==================================

The lines below might hint at the cause of the crash.
If they do not help you then please submit a bug report at
root.cern.ch/bugs. Please post the ENTIRE stack trace
from above as an attachment in addition to anything else
that might help us fixing this issue.

#5 0x00007fd838bfd1a0 in TGClient::GetRoot() const () from /home/Federico/root/lib/libGui.so
#6 0x000000000040227a in main ()

[/ul]

i’m using scientific linux 6
thank you

Exactly which ROOT version and which tutorial?

ROOT 5 and i use this code

#include <TGClient.h> #include <TCanvas.h> #include <TF1.h> #include <TRandom.h> #include <TGButton.h> #include <TGFrame.h> #include <TRootEmbeddedCanvas.h> #include <RQ_OBJECT.h> class MyMainFrame { RQ_OBJECT("MyMainFrame") private: TGMainFrame *fMain; TRootEmbeddedCanvas *fEcanvas; public: MyMainFrame(const TGWindow *p,UInt_t w,UInt_t h); virtual ~MyMainFrame(); void DoDraw(); }; Writing a Graphical User Interface 391 MyMainFrame::MyMainFrame(const TGWindow *p,UInt_t w,UInt_t h) { // Create a main frame fMain = new TGMainFrame(p,w,h); // Create canvas widget fEcanvas = new TRootEmbeddedCanvas("Ecanvas",fMain,200,200); fMain->AddFrame(fEcanvas, new TGLayoutHints(kLHintsExpandX| kLHintsExpandY, 10,10,10,1)); // Create a horizontal frame widget with buttons TGHorizontalFrame *hframe = new TGHorizontalFrame(fMain,200,40); TGTextButton *draw = new TGTextButton(hframe,"&Draw"); draw->Connect("Clicked()","MyMainFrame",this,"DoDraw()"); hframe->AddFrame(draw, new TGLayoutHints(kLHintsCenterX,5,5,3,4)); TGTextButton *exit = new TGTextButton(hframe,"&Exit", "gApplication->Terminate(0)"); hframe->AddFrame(exit, new TGLayoutHints(kLHintsCenterX,5,5,3,4)); fMain->AddFrame(hframe, new TGLayoutHints(kLHintsCenterX,2,2,2,2)); // Set a name to the main frame fMain->SetWindowName("Simple Example"); // Map all subwindows of main frame fMain->MapSubwindows(); // Initialize the layout algorithm fMain->Resize(fMain->GetDefaultSize()); // Map main frame fMain->MapWindow(); } void MyMainFrame::DoDraw() { // Draws function graphics in randomly choosen interval TF1 *f1 = new TF1("f1","sin(x)/x",0,gRandom->Rndm()*10); f1->SetFillColor(19); f1->SetFillStyle(1); f1->SetLineWidth(3); f1->Draw(); TCanvas *fCanvas = fEcanvas->GetCanvas(); fCanvas->cd(); fCanvas->Update(); } MyMainFrame::~MyMainFrame() { // Clean up used widgets: frames, buttons, layouthints fMain->Cleanup(); delete fMain; } void example() { // Popup the GUI... new MyMainFrame(gClient->GetRoot(),200,200); }

Hi,

I have no problem with this script on SLC6 64bit, gcc 4.8 with ROOT v5-34-00-patches. Which exact version of ROOT? Which compiler? How did you install it? How do you run ROOT and your script?
And BTW, you could also use this version of your script:

[code]#include <TGClient.h>
#include <TCanvas.h>
#include <TF1.h>
#include <TRandom.h>
#include <TGButton.h>
#include <TGFrame.h>
#include <TRootEmbeddedCanvas.h>

class MyMainFrame : public TGMainFrame
{
private:
TRootEmbeddedCanvas *fEcanvas;
public:
MyMainFrame(const TGWindow *p,UInt_t w,UInt_t h);
virtual ~MyMainFrame();
void DoDraw();

ClassDef(MyMainFrame, 0)
};

MyMainFrame::MyMainFrame(const TGWindow *p,UInt_t w,UInt_t h) : TGMainFrame(p, w, h) {
// Create canvas widget
fEcanvas = new TRootEmbeddedCanvas(“Ecanvas”,this,200,200);
AddFrame(fEcanvas, new TGLayoutHints(kLHintsExpandX| kLHintsExpandY,10,10,10,1));
// Create a horizontal frame widget with buttons
TGHorizontalFrame *hframe = new TGHorizontalFrame(this,200,40);
TGTextButton *draw = new TGTextButton(hframe,"&Draw");
draw->Connect(“Clicked()”,“MyMainFrame”,this,“DoDraw()”);
hframe->AddFrame(draw, new TGLayoutHints(kLHintsCenterX,5,5,3,4));
TGTextButton *exit = new TGTextButton(hframe,"&Exit",“gApplication->Terminate(0)”);
hframe->AddFrame(exit, new TGLayoutHints(kLHintsCenterX,5,5,3,4));
AddFrame(hframe, new TGLayoutHints(kLHintsCenterX,2,2,2,2));
// Set a name to the main frame
SetWindowName(“Simple Example”);
// Map all subwindows of main frame
MapSubwindows();
// Initialize the layout algorithm
Resize(GetDefaultSize());
// Map main frame
MapWindow();
}

void MyMainFrame::DoDraw() {
// Draws function graphics in randomly choosen interval
TF1 *f1 = new TF1(“f1”,“sin(x)/x”,0,gRandom->Rndm()*10);
f1->SetFillColor(19);
f1->SetFillStyle(1);
f1->SetLineWidth(3);
f1->Draw();
TCanvas *fCanvas = fEcanvas->GetCanvas();
fCanvas->cd();
fCanvas->Update();
}

MyMainFrame::~MyMainFrame() {
// Clean up used widgets: frames, buttons, layouthints
Cleanup();
}

void example2() {
// Popup the GUI…
new MyMainFrame(gClient->GetRoot(),200,200);
}
[/code]
Cheers, Bertrand.

gcc 4.4.7 root 5 and to install root i’ve used this http://wiki.ubuntu-it.org/Programmazione/RootCern

Thanks, but it still doesn’t tell me which version of ROOT you are using…