What are the rules for painting to the screen?
My end goal is to put the TCanvas into a class and paint from there, but for now I think that maybe looking at a less complicated example might help. Below is some code that compiles and paints to the screen, on my computer.
# include <TApplication.h>
# include <TCanvas.h>
# include <TH1D.h>
# include <thread>
# include <chrono>
//TCanvas canvas ("fCanvas", "fCanvas", 600, 400);
int main ( int argc, char* argv[] )
{
TApplication app ("app",&argc,argv);
TCanvas canvas ("fCanvas", "fCanvas", 600, 400);
//TCanvas* canvas = new TCanvas("fCanvas", "fCanvas", 600, 400);
TH1D h ("h","h",10,0,10);
h.Fill(1);
h.Fill(2);
h.Fill(2);
h.Fill(2);
h.Fill(3);
h.Fill(3);
h.Draw();
canvas.Update();
canvas.Draw();
std::this_thread::sleep_for( std::chrono::seconds(3) );
return 0;
}
You may notice some commented-out lines. If I use either of those definitions of canvas
, using the appropriate member access operators on the later-called Update
and Draw
methods, the application crashes after printing a blank TCanvas-window to the screen. It also crashes if I change app
and h
to pointers.
If I try to instantiate a class using any sort of ROOT object at all, it crashes the application.
Right now, I'm compiling with MSVC++'s cl.exe
and linking with link.exe
. I'm working on a 64-bit Windows 7 Enterprise N. I'm trying to port an application that I built in Unix, for which a simple new TApplication("name",0,0);
at the start of main
made everything work.
So, to reiterate: how can I get my histograms onto the screen in this OS, and maybe others? I doubt that I'll be able to understand the "why", but it might be nice to write something about that for others reading this who can. Otherwise, just a step-by-step description of how to use these objects to paint would be wonderful.
Many thanks for any help on this; I'll gladly provide more information / examples if that should prove useful.
Update: it works in my particular case if I compile with something like
cl -nologo -DWIN32 -W3 -D_WINDOWS -Z7 -MDd -GR -EHsc main.cxx -I %ROOTSYS%\include -FIw32pragma.h /link -debug -LIBPATH:%ROOTSYS%\lib libCore.lib libRIO.lib libHist.lib libGpad.lib
Not sure why.
See https://root.cern.ch/phpBB3/viewtopic.php?f=3&t=3402&p=85329&hilit=Vector+stl+of+TH1F*+Objects#p85329 .