# Draw canvases produced in batch mode

**URL:** <https://root-forum.cern.ch/t/draw-canvases-produced-in-batch-mode/19893>\
**Category:** ROOT\
**Created:** [September 24, 2015, 1:41pm UTC](https://root-forum.cern.ch/t/draw-canvases-produced-in-batch-mode/19893 "2015-09-24T13:41:04Z")\
**Posts on this page:** 1\
**Showing post:** 1

<div class="post-metadata">

**Author:** ![Nicola\_Mori](https://root-forum.cern.ch/user_avatar/root-forum.cern.ch/nicola_mori/32/23583_2.png) [@Nicola\_Mori](https://root-forum.cern.ch/u/Nicola_Mori)\
**Post date:** [September 24, 2015, 1:41pm UTC](https://root-forum.cern.ch/t/draw-canvases-produced-in-batch-mode/19893/1 "2015-09-24T13:41:04Z")

</div>

I need to produce many canvases in batch in my application. What I do is something like this:

```auto
gROOT->SetBatch(kTRUE);
std::vector<TCanvas*> canvases;
for(int i = 0; int < nCanvases; i++){
	TCanvas *c = new TCanvas;
	TH1F *h1 = new TH1F(...);
	TH1F *h2 = new TH1F(...);
	// Fill h1 and h2 and then:
	h1->Draw();
	h2->Draw("SAME");
	canvases.push_back(c);
}
gROOT->SetBatch(kFALSE);
```

At the end I have a vector of TCanvas. At this point the user may ask the GUI to show a certain canvas, so I need to draw it. The problem is that it seems that if a Canvas is produced when Root is in batch mode then it is not displayed. Calling TCanvas::SetBatch(kFALSE) before drawing results in a segfault. I attach a small example to illustrate the issue (compile with: g++ -g `root-config --cflags --libs` batch.cpp).  
Thanks for the help.  
[batch.cpp](https://root-forum.cern.ch/uploads/default/original/2X/f/f7c3241ceacf21893797af05237ed19cedb08467.cpp) (520 Bytes)

---

_[View the full topic](https://root-forum.cern.ch/t/draw-canvases-produced-in-batch-mode/19893)._
