_ROOT Version:6.14/06
_Platform: wsl
_Compiler:g++ 7.3.0
I created a test.C file containing the following code:
#include<TTree.h>
#include<TRandom.h>
class TestClass
{
public:
TTree *fTree;
TestClass() : fTree(0) {};
TTree* GetTree()
{
// the following line causes crash
// everything is find if it is commented out
if (fTree!=0) return fTree;
TTree *fTree = new TTree("t","tree");
double v, c;
fTree->Branch("v",&v,"v/D");
fTree->Branch("c",&c,"c/D");
for (int i=0; i<10; i++) {
v = gRandom->Gaus();
c = gRandom->Rndm();
fTree->Fill();
}
return fTree;
}
};
void test()
{
TestClass tc;
tc.GetTree()->Draw("v:c");
}
With if (fTree!=0) return fTree;
:
$ root test.C
root [0]
Processing test.C...
0
Info in <TCanvas::MakeDefCanvas>: created default TCanvas with name c1
*** stack smashing detected ***: <unknown> terminated
Without it, everything is fine.
If I compile it: root test.C++
, everything is fine as well.
Did I do something wrong here?