#include "TCanvas.h" #include "TROOT.h" #include "TH1F.h" #include "TApplication.h" int main(){ TApplication app("", 0, NULL); gROOT->SetBatch(kTRUE); // Commenting this out makes the program work as expected TCanvas *c = new TCanvas; TH1F *h1 = new TH1F("h1", "h1", 10, 0, 1); TH1F *h2 = new TH1F("h2", "h2", 10, 0, 1); h1->Draw(); h2->Draw("SAME"); gROOT->SetBatch(kFALSE); // c->SetBatch(kFALSE); // This will give a segfault during draw if the canvas was produced in batch mode c->Draw(); app.Run(); }