RE: TPad seg fault

From: Olivier Couet <Olivier.Couet_at_cern.ch>
Date: Fri, 3 Sep 2010 10:00:48 +0200


Hi Akira,
I managed to reproduce your problem with a much simpler macro. I am debugging that one now.

{

    Int_t i,j;
    TCanvas* can = new TCanvas("can", "can", 1200, 800);     can->Divide(4, 4, 0.001, 0.001);
    TPad* pad[16];

    for (i = 0; i < 16; i++) {

       pad[i] = new TPad(Form("p%d",i), Form("p%d",i), 0, 0, 1, 1);     }

    for (i = 0; i < 3; i++) {

       for (j = 0; j < 16; j++) {
          can->cd(j + 1);
          gPad->DrawFrame(0, 0, 1, i + 1);
          pad[j]->Draw();
       }

    }
}

Cheers,
Olivier
-----Original Message-----
From: owner-roottalk_at_root.cern.ch [mailto:owner-roottalk_at_root.cern.ch] On Behalf Of OKUMURA, Akira Sent: Friday, September 03, 2010 12:00 AM To: roottalk (Mailing list discussing all aspects of the ROOT system.) Cc: OKUMURA, Akira
Subject: [ROOT] TPad seg fault

Hello ROOTers,

The following code cause a seg fault because TPad instances seem to be deleted after the 1st loop of j is ended. Would you tell me what the problem is in the code? Using 5.27 and trunk on OS X 10.6 and SL5.

#include "TCanvas.h"
#include "TPad.h"
#include <iostream>

static const Int_t kSegmentN = 3;
static const Int_t kSampleN = 16;

void tmp()
{
  TCanvas* can = new TCanvas("can", "can", 1200, 800);   can->Divide(4, 4, 1e-10, 1e-10);

  TPad* pad_sigma[kSampleN];
  TPad* pad_res[kSampleN];

  for(Int_t i = 0; i < kSampleN; i++){
    pad_sigma[i] = new TPad(Form("pad_sigma%02d", i), Form("pad_sigma%02d", i), 0, 0, 1, 1);     pad_res[i] = new TPad(Form("pad_res%02d", i), Form("pad_res%02d", i), 0, 0, 1, 1);

    can->cd(i + 1);
    gPad->SetBottomMargin(0.5);
    pad_sigma[i]->SetMargin(0.1, 0.1, 0.3, 0.5);     pad_sigma[i]->SetFillStyle(0);

    can->cd(i + 1);
    pad_res[i]->SetMargin(0.1, 0.1, 0.1, 0.7);     pad_res[i]->SetFillStyle(0);
  } // i

  for(Int_t i = 0; i < kSegmentN; i++){
    for(Int_t j = 0; j < kSampleN; j++){

      can->cd(j + 1);
      gPad->DrawFrame(0, 0, 1, i + 1);

      pad_sigma[j]->Draw();
      pad_sigma[j]->cd();
      gPad->DrawFrame(0, 0, 1, i + 1);

      pad_res[j]->Draw();
      pad_res[j]->cd();
      gPad->DrawFrame(0, 0, 1, i + 1);

    } // j
    // can->Update();
  } // i
}

Regards,

--
OKUMURA, Akira oxon@{astro.isas.jaxa.jp,stanford.edu}
Institute of Space and Astronautical Science (ISAS/JAXA) Now at KIPAC/SLAC/Stanford Varian Physics #306
382 Via Pueblo Mall, MC 406 Stanford, CA94305 TEL 650-736-0971/FAX 650-724-5065 Skype : okumura.akira
Received on Fri Sep 03 2010 - 10:00:56 CEST

This archive was generated by hypermail 2.2.0 : Fri Sep 03 2010 - 17:50:02 CEST