Hi,
I have a problem in deleting a TCanvas. I’m writing a code which loops over some events and for each event I would like to open a canvas, analyse the event, reset the content and move to the following event.
But whenever I try to delete my canvas, I get the following error message when my code reaches the end:
root [3] Error in : BadWindow (invalid Window parameter) (TGDockHideButton XID: 44040351, XREQ: 2)
Here is a small piece of the code which gives me this error, I might be doing something very silly:
#include “TH2F.h”
#include “TCanvas.h”
#include “TROOT.h”
#include “TH1.h”
#include “Riostream.h”
#include
#include
#include
#include
#include <string.h>
#include
Int_t AZ1[4] = {3,1,2,3};
Int_t AZ2[3] = {2,3,4};
void test()
{
TString HistoName;
Int_t *momA;
TCanvas *canv ;
TH2F **ChIoSi;
for(int k=1;k<3;k++)//loop on Z : each Z is a new event
{
int z=k;
cout<<“"<<endl;
cout<<" Z = "<<z<<endl;
cout<<"”<<endl<<flush;
momA = NULL;
if(z==1) momA = AZ1;
else if(z==2) momA =AZ2;
ChIoSi = new TH2F*[momA[0]];
// canv= new TCanvas(Form(“canv%d”,z),Form(“canv%d”,z));
canv= new TCanvas(“canv”,“canv”);
int row = 2*momA[0];
canv->Divide(row,3);
for(int j=0;j<momA[0];j++)//loop on A
{
ChIoSi[j]=NULL;
//Reading some histos from a file.....
ChIoSi[j] = new TH2F("testh","testh",10,0,10,10,0,10);
ChIoSi[j] ->SetBinContent(4,6,10);
//--------------------------
canv->cd(j+1);
if(ChIoSi[j]!=NULL)
{
ChIoSi[j]->Draw("zcol");
}
else cout<<"chiosi = null"<<endl;
canv->Modified();
canv->Update();
}//loop on A
//—need to reset everything before going to the next even
ChIoSi = NULL;
if(canv!=NULL)
{
//canv->Clear();
canv->Closed();
//canv = NULL;
delete canv;
}
//--------------------------------
} //loop on Z
cout<<“OUT”<<endl<<flush;
}
I always reach the end of the code (ie I see the output “OUT” before the error message shows up.
Thank you very much for your help
Best regards
Paola