[Solved] Canvas won't close!

Hi,

There is something weird with TCanvas. When typing in the interpreter :

root [0] TCanvas *can = new TCanvas(); root [1] can->Close(); everything works fine : the canvas opens then closes itself.

But when running or compiling the following macro :

int test() { int h; cin>>h; TCanvas *can=new TCanvas(); cout<<"Canvas should be created !!!"<<endl; cin>>h; can->Close(); cout<<"Canvas must be closed !!!"<<endl; cin>>h; cout<<"Canvas still there ???"<<endl; cin>>h; return 0; }
the canvas is created while it should close itself, and will never close !!!

Could anybody tell me what’s wrong ?

Thanks.

PS : I am using 5.12/00e root version.

Edit : there is something weird with the forum and/or firefox : “<>h;” in the code should be read as “<<end ;” followed by “cin [sup][sup] h;”
(See René’s suggestion about html…)

1 Like

No idea ? Is anybody at least able to reproduce this problem ? If so, is it a bug or do I misunderstand the TCanvas::Close() usage ?

You must tell ROOT to process the pending events. Pending events
are executed when you type CR after a command or when the macro completes. Modify your script as follows

int test() { int h; cin>>h; TCanvas *can=new TCanvas(); gSystem->ProcessEvents(); cout<<"Canvas should be created !!!"<<endl>>h; delete can; //can->Close(); gSystem->ProcessEvents(); cout<<"Canvas must be closed !!!"<<endl>>h; cout<<"Canvas still there ???"<<endl>>h; return 0; }

Note that to post code like above, YOU MUST CLICK on the item “Disable HTML in this post”

Rene

Ok, it’s better now, thanks.

[quote=“brun”]Note that to post code like above, YOU MUST CLICK on the item “Disable HTML in this post”[/quote]Thanks again, I didn’t notice that…