Re: [ROOT] Unexpected behavior of object's destructor: interpreted, on stack

From: Valeri Fine (fine@bnl.gov)
Date: Sat Feb 02 2002 - 17:24:31 MET


Hello
Can you check your problem is still persisting with Qt-evaluation version of
ROOT

http://www.usatlas.bnl.gov/~fine/QtRootDownload.html

and let me know.

 Mean time I'll try your example ( as soon as I reach my office table).

  Thank you,
                         Valeri


----- Original Message -----
From: <eoltman@imagoscientific.com>
To: <roottalk@pcroot.cern.ch>
Sent: Saturday, February 02, 2002 8:32 AM
Subject: [ROOT] Unexpected behavior of object's destructor: interpreted, on
stack


> Hello,
>
> I have observed strange destructor behavior for an
> object I wrote. (I have included a simple class that
> demonstrates the problem):
>
> 1.  If the interpreted object is created on the stack,
>     it usually causes root to crash, but not always -
>     see two root sessions below (taken in sequence
>     w/out any intervening commands)
>
> 2.  Problem does NOT occur if object is created
>     on the heap when I delete it
>
> 3.  The problem does NOT occur when I compile
>     (e.g. replace .L test.cpp w/ .L test.cpp++)
>
> I am using Root V3.2/07 on Windows XP.
>
> Any idea why this behavior?
>
> Thanks,
> Ed Oltman
>
> ================ sample root sessions ==================
>
> C:\BowlV>root
>  the current keyboard layout is 437
>   *******************************************
>   *                                         *
>   *        W E L C O M E  to  R O O T       *
>   *                                         *
>   *   Version   3.02/07   10 January 2002   *
>   *                                         *
>   *  You are welcome to visit our Web site  *
>   *          http://root.cern.ch            *
>   *                                         *
>   *******************************************
>
> Compiled for win32.
>
> CINT/ROOT C/C++ Interpreter version 5.15.25, Jan 6 2002
> Type ? for help. Commands must be C++ statements.
> Enclose multiple statements between { }.
> root [0] .L test.cpp
> root [1] Demo p
> root [2] TCanvas *c = new TCanvas()
> root [3] p.Make()
>  **********
>  **    1 **SET ERR           1
>  **********
> root [4] p.Draw()
> root [5] .q
>
> C:\BowlV>root
>  the current keyboard layout is 437
>   *******************************************
>   *                                         *
>   *        W E L C O M E  to  R O O T       *
>   *                                         *
>   *   Version   3.02/07   10 January 2002   *
>   *                                         *
>   *  You are welcome to visit our Web site  *
>   *          http://root.cern.ch            *
>   *                                         *
>   *******************************************
>
> Compiled for win32.
>
> CINT/ROOT C/C++ Interpreter version 5.15.25, Jan 6 2002
> Type ? for help. Commands must be C++ statements.
> Enclose multiple statements between { }.
> root [0] .L test.cpp
> root [1] Demo p
> root [2] TCanvas *c = new TCanvas()
> root [3] p.Make()
>  **********
>  **    1 **SET ERR           1
>  **********
> root [4] p.Draw()
> root [5] .q
> Error: Symbol i is not defined in current scope  FILE:C:\BowlV\test.cpp
LINE:27
> *** Interpreter error recovered ***
>
> C:\BowlV>
>
>  --Then I get a "root.exe has encountered a problem and needs to
> close..."
>  box...
>
> ================ demonstration class ==================
>
> #include <string.h>
> #include <stdio.h>
> #include <stdlib.h>
> #include "TGraph.h"
> #include "TCanvas.h"
> #include "TPad.h"
> #include "TROOT.h"
> #include "TF1.h"
> class Demo
> {
> private:
>     TGraph *m_pGraph[3];
>     bool noCanvas();
> public:
>     Demo();
>     ~Demo();
>     void Make();
>     void Draw();
> #if !defined(__CINT__) || defined(__MAKECINT__)
>     ClassDef(Demo,0)
> #endif
> };
> #if !defined(__CINT__) || defined(__MAKECINT__)
> ClassImp(Demo)
> #endif
> Demo::Demo()
> {
>     for (int i=0;i<3;i++) m_pGraph[i]=0;
> }
> Demo::~Demo()
> {
>     for(int i=0;i<3;i++)if (m_pGraph[i]) delete m_pGraph[i];
> }
> void Demo::Make()
> {
>     double x[20],y[20];
>     for(int i=0;i<20;i++) x[i] = 6.283*i/20.;
>     for(i=0;i<3;i++)
>     {
>         if (m_pGraph[i]) delete m_pGraph[i];
>         for(int j=0;j<20;j++) y[j] = sin(x[j] + .5*i);
>         m_pGraph[i] = new TGraph(20,x,y);
>         m_pGraph[i]->SetMarkerColor(1+i);
>         m_pGraph[i]->SetMarkerStyle(20);
>
> // now, fit graph...
>         TF1 *pf = new TF1("fit","sin(x+[0])",0.,6.283);
>         m_pGraph[i]->Fit(pf,"qw");
>         delete pf;
>     }
> }
> void Demo::Draw()
> {
>     if (noCanvas()) return;
>     gPad->GetCanvas()->Clear();
>     m_pGraph[0]->Draw("AP");
>     for(int i=1;i<3;i++)
>     {
>         m_pGraph[i]->Draw("P");
>     }
> }
> bool Demo::noCanvas()
> {
>     if (gROOT->GetListOfCanvases()->IsEmpty())
>     {
>         printf(" No canvas exists: Please create one...\n");
>         return true;
>     }
>     return false;
> }
>
>



This archive was generated by hypermail 2b29 : Sat Jan 04 2003 - 23:50:40 MET