Stack trace error when trying to update canvas

I have a rather complicated gui based macro. Here’s the skeleton

[code]class myClass{
TCanvas *c;
};

void myClass::ifClicked(TH1D h){
// TFile blah blah here
h = (TH1D
)file->Get(“histName”);
this->h->Draw(“same”);

this->c->Modified();
this->c->Update();
}
constructor {
this->c = new TCanvas(//params);
}
[/code]
I tried initializing the canvas object in the ifClicked method, it works, but well it keeps updating everytime, I just want the histograms to update. I tried with dummy histograms and it works, but only when the canvas is initialized in the method.

I have been scratching my head for quite some time trying to figure out why I get an error like this, only when the canvas is initialized in the constructor.

[color=#BF0000] *** Break *** segmentation violation

===========================================================
There was a crash (#7 0xb75d40c8 in SigHandler(ESignals) () from /home/catsFlying/Packages/root-6.04.04/lib/libCore.so).
This is the entire stack trace of all threads:

#0 0xb7722d40 in __kernel_vsyscall ()
#1 0xb7125ab3 in __waitpid_nocancel () at …/sysdeps/unix/syscall-template.S:81
#2 0xb70ad02e in do_system (line=line
entry=0xbab0f48 “/home/catsFlying/Packages/root-6.04.04/etc/gdb-backtrace.sh 26375 1>&2”) at …/sysdeps/posix/system.c:148
#3 0xb70ad400 in __libc_system (line=line
entry=0xbab0f48 “/home/catsFlying/Packages/root-6.04.04/etc/gdb-backtrace.sh 26375 1>&2”) at …/sysdeps/posix/system.c:184
#4 0xb722abdb in system (line=0xbab0f48 “/home/catsFlying/Packages/root-6.04.04/etc/gdb-backtrace.sh 26375 1>&2”) at pt-system.c:28
#5 0xb75d1c84 in TUnixSystem::StackTrace() () from /home/catsFlying/Packages/root-6.04.04/lib/libCore.so
#6 0xb75d3f6b in TUnixSystem::DispatchSignals(ESignals) () from /home/catsFlying/Packages/root-6.04.04/lib/libCore.so
#7 0xb75d40c8 in SigHandler(ESignals) () from /home/catsFlying/Packages/root-6.04.04/lib/libCore.so
#8 0xb75ce2d3 in sighandler(int) () from /home/catsFlying/Packages/root-6.04.04/lib/libCore.so
#9 0xb7600606 in textinput::TerminalConfigUnix::HandleSignal(int) () from /home/catsFlying/Packages/root-6.04.04/lib/libCore.so
#10 0xb7600651 in (anonymous namespace)::TerminalConfigUnix__handleSignal(int) () from /home/catsFlying/Packages/root-6.04.04/lib/libCore.so
#11
#12 0xb735f74e in ?? ()
#13 0xb735f573 in ?? ()
#14 0xaefe402a in ?? ()
#15 0xb4c43b6c in TClingCallFunc::exec(void*, void*) const () from /home/catsFlying/Packages/root-6.04.04/lib/libCling.so
#16 0xb4c5066f in TClingCallFunc::Exec(void*, TInterpreterValue*) () from /home/catsFlying/Packages/root-6.04.04/lib/libCling.so
#17 0xb4c018ae in TCling::CallFunc_Exec(CallFunc_t*, void*) const () from /home/catsFlying/Packages/root-6.04.04/lib/libCling.so
#18 0xb75225cc in TQConnection::ExecuteMethod() () from /home/catsFlying/Packages/root-6.04.04/lib/libCore.so
#19 0xb755ab48 in TQObject::Emit(char const*) () from /home/catsFlying/Packages/root-6.04.04/lib/libCore.so
#20 0xaeb9a192 in TGCheckButton::HandleButton(Event_t*) () from /home/catsFlying/Packages/root-6.04.04/lib/libGui.so
#21 0xaebf00dc in TGFrame::HandleEvent(Event_t*) () from /home/catsFlying/Packages/root-6.04.04/lib/libGui.so
#22 0xaecb09dd in TGClient::HandleEvent(Event_t*) () from /home/catsFlying/Packages/root-6.04.04/lib/libGui.so
#23 0xaecb0cfa in TGClient::ProcessOneEvent() () from /home/catsFlying/Packages/root-6.04.04/lib/libGui.so
#24 0xaecb0d5e in TGClient::HandleInput() () from /home/catsFlying/Packages/root-6.04.04/lib/libGui.so
#25 0xaecb0d8b in TGInputHandler::Notify() () from /home/catsFlying/Packages/root-6.04.04/lib/libGui.so
#26 0xb75d4818 in TUnixSystem::DispatchOneEvent(bool) () from /home/catsFlying/Packages/root-6.04.04/lib/libCore.so
#27 0xb7539e38 in TSystem::InnerLoop() () from /home/catsFlying/Packages/root-6.04.04/lib/libCore.so
#28 0xb7537a0d in TSystem::Run() () from /home/catsFlying/Packages/root-6.04.04/lib/libCore.so
#29 0xb755f880 in TApplication::Run(bool) () from /home/catsFlying/Packages/root-6.04.04/lib/libCore.so
#30 0xb73816d4 in TRint::Run(bool) () from /home/catsFlying/Packages/root-6.04.04/lib/libRint.so
#31 0x08048cec 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.

#12 0xb735f74e in ?? ()
#13 0xb735f573 in ?? ()
#14 0xaefe402a in ?? ()
#15 0xb4c43b6c in TClingCallFunc::exec(void*, void*) const () from /home/catsFlying/Packages/root-6.04.04/lib/libCling.so
#16 0xb4c5066f in TClingCallFunc::Exec(void*, TInterpreterValue*) () from /home/catsFlying/Packages/root-6.04.04/lib/libCling.so
#17 0xb4c018ae in TCling::CallFunc_Exec(CallFunc_t*, void*) const () from /home/catsFlying/Packages/root-6.04.04/lib/libCling.so
#18 0xb75225cc in TQConnection::ExecuteMethod() () from /home/catsFlying/Packages/root-6.04.04/lib/libCore.so
#19 0xb755ab48 in TQObject::Emit(char const*) () from /home/catsFlying/Packages/root-6.04.04/lib/libCore.so
#20 0xaeb9a192 in TGCheckButton::HandleButton(Event_t*) () from /home/catsFlying/Packages/root-6.04.04/lib/libGui.so
#21 0xaebf00dc in TGFrame::HandleEvent(Event_t*) () from /home/catsFlying/Packages/root-6.04.04/lib/libGui.so
#22 0xaecb09dd in TGClient::HandleEvent(Event_t*) () from /home/catsFlying/Packages/root-6.04.04/lib/libGui.so
#23 0xaecb0cfa in TGClient::ProcessOneEvent() () from /home/catsFlying/Packages/root-6.04.04/lib/libGui.so
#24 0xaecb0d5e in TGClient::HandleInput() () from /home/catsFlying/Packages/root-6.04.04/lib/libGui.so
#25 0xaecb0d8b in TGInputHandler::Notify() () from /home/catsFlying/Packages/root-6.04.04/lib/libGui.so
#26 0xb75d4818 in TUnixSystem::DispatchOneEvent(bool) () from /home/catsFlying/Packages/root-6.04.04/lib/libCore.so
#27 0xb7539e38 in TSystem::InnerLoop() () from /home/catsFlying/Packages/root-6.04.04/lib/libCore.so
#28 0xb7537a0d in TSystem::Run() () from /home/catsFlying/Packages/root-6.04.04/lib/libCore.so
#29 0xb755f880 in TApplication::Run(bool) () from /home/catsFlying/Packages/root-6.04.04/lib/libCore.so
#30 0xb73816d4 in TRint::Run(bool) () from /home/catsFlying/Packages/root-6.04.04/lib/libRint.so
#31 0x08048cec in main ()

[/color]

Th code you show here cannot be run …
It is hard to tell what is wrong.
the “idea” seems correct though …
h is an output parameter of ifClicked ?

[quote=“couet”]Th code you show here cannot be run …
It is hard to tell what is wrong.
the “idea” seems correct though …
h is an output parameter of ifClicked ?[/quote]

I used ifClicked just as some func name, so nothing special about it.

The idea is like this :

  1. Declare the TCanvas object in the class def (TCanvas *canvas)
  2. Create the TCanvas object in the constructor (this->canvas = new TCanvas(“c”, “”, 900, 460))
  3. Click a button to call a function (this->updateCanvas())
  4. this->updateCanvas() { //some code to read the file and close it there
    myFunc(TH1D* fileName, TH1D *hName) }
  5. myFunc(TH1D* fileName, TH1D *hName) {
    //Open the file fileName // works
    // Read the histogram (hName)// works
    // Disconnect the histogram from file
    // this->canvas->Update() // fails
    // this->canvas->Modified() // fails
    }

The only thing that seemed to work is reinitializing the canvas in the function, but all I want is to update the canvas with a new histogram and keep it like that even after the file is closed. As I wanted to read the histogram through GUI later on from the canvas directory.

I suspected if file opening and closing is a problem, but didn’t seem like that. Looking forward for more advice on this problem.

It would be helpfull if you could provide a small program (we can run) reproducing the issue.

Unfortunately my macro is really huge, and I debugged all places and sounds like this is the only one place where I have the issue (TCanvas).

Turns out the canvas object is not the same in the updateCanvas function as it was initialized in the constructor. I am not sure why this is the case.

Edit :
I guess I figured out the issue, but not solved. I have a constructor that’s drawing another window through the constructor defined in the same class.

Eg :

class myClass {
myClass() // normal window that passes arguments to draw the second myClass below
myClass(//someother things) //draws windows

}

So the canvas object I happen to call doesn’t belong to the window it calls.

When I call the second constructor, it owns is space of all the objects of the same class i.e. I would like to have a window that owns the other windows and can access objects based on events from other windows. How can I do it ?

or simply put, I want to have window w1, that can spawn window w2, w3 say, but should do the following :
events(w2, w3) -> Fetch Objects to w1 and modify the canvas belonging to window w1

It is really difficult to help you further without code.
“window” is a class you wrote ?