I am using TCanvas within a subroutine of a Visual Studio 2008 project. The following is an extract of the code (the entire code is much too long to post here). The code compiles fine and runs fine up to “my_canvas->Update();” where it produces a
“Unhandled exception at 0x016250bd in trad.exe: 0xC0000005: Access violation reading location 0x00000090.”. No Canvas appears.
My question is: what am I missing to get the actual Canvas to draw? I assume that once the Canvas is actually displayed, the “my_canvas->Update();” should work too.
Any enlightment would be very much appreciated!
Wolf
// Create a TCanvas.
TCanvas* my_canvas = new TCanvas(“my_canvas”,“Histogram Example”,200,10,600,400);
// Create a 1D histogram, set its fill colour, and draw it on the current TPad
TH1F *hist = new TH1F(“hist”,“Exponential distribution”,100,0.,5.);
hist->SetFillColor(3);
hist->Draw();
// Prepare the random number generator.
gRandom->SetSeed();
// Loop generating data according to an exponential.
Float_t data;
Int_t dummy;
for ( Int_t i=0; i<10000; i++) {
data = - log( gRandom->Rndm(dummy) );
hist->Fill(data);
if ( i%100 == 0 ) {
my_canvas->Modified();
my_canvas->Update();
}
}
I do not see anything wrong with your code. I can run it on Linux, Mac and windows. Which version are you using? if older than 5.24 please try 5.24.
Do not post this type of message to this thread reserved for the announcement of user applications based on ROOT. Post your message to the “Discussion” or “Support” threads.
I do. Question - do I need to first draw some Windows Canvas before I can draw the ROOT Canvas inside the Windows Canvas or should I be able to directly draw the ROOT Canvas from my Visual Studio application without further Graphics Display Interface?
Further to my previous message - I just came across root.cern.ch/root/Version51000.news.html where a MFCRoot Canvas is shown similar to what I would like to create. I am not very familiar with MFC. I am familiar with Visual Studio and (at the basic level) Root. So my question would be: what concrete steps do I need to take to get such a graphical output from a VS2008 C++ program? What libraries do I need? What files do I need to include into my VS2008 code and what functions do I need to call?
Here is a demo application based on the code you sent. Hope this will help.
You can also take a look in the $ROOTSYS/test directory for several example applications and Makefile.win32, which is the nmake makefile for these applications.
First, you should try with the same configuration than the ROOT binaries you downloaded (e.g debug or release).
And how do you start the application? from Visual Studio?
Do you have any compilation error/warning?
Are your environment variables (ROOTSYS and PATH) correctly set?
I am not quite sure what you mean by “try with the same configuration than the ROOT binaries you downloaded”. I have installed Root 5.24/00 for windows…
I am running my application with visual studio (not command line).
There are no errors, but two warnings (one related to conversion from float to double) and LINK : C:\Personal\wolfschu\Debug\wolfschu.exe not found or not built by the last incremental link; performing full link.
I checked the ROOTSYS and PATH and they seem to be correct. However, I am not running ROOT whilst running my VS2008 application.
Under normal circumstances, should I be able to run the VS2008 sln you kindly provided as is or is there something else I need to take care of?
There are several versions of the binaries: MSVC++7.1, MSVC++9.0, each in debug and release… So you probably downloaded root_v5.24.00.win32.vc90.tar.gz?
And the solution should be usable as is. But I’ll cross check tomorrow.
Further to my previous email, here are the details of the error message I get from VS2008:
libCore.dll!100750bd()
[Frames below may be incorrect and/or missing, no symbols loaded for libCore.dll]
libHist.dll!016b5ef0()
libHist.dll!0164aeba()
libHist.dll!0164d03e()
libGpad.dll!0017ddbc()
libGpad.dll!001653f5()
wolfschu.exe!main(int argc=0, char * * argv=0x7efde000) Line 34 + 0x14 bytes C++
I have just copied the wolfschu.cpp into the macros directory of root and then tried to run it using “.x wolfschu.cpp”. I get the following error message:
“root [5] .x wolfschu.cpp
Error: cannot open file “C:\Program Files” (0)
Expecting . in filename
*** Interpreter error recovered ***”
I have installed root into “C:\Program Files (x86)”. Could that be an issue?
Do not untar in a directory with a name containing blank characters.
…[/quote]
And as previously said, try the root macros in tutorials first, to be sure everything works correctly.
Many thanks, Bertrand. That actually has solved the initial problem of getting the Canvas to appear.
The problem I am facing now is that when I run my application, after the Canvas has been drawn, it freezes the Canvas window (as in when I go over it with my mouse, the “busy” sign appears). I am opening my Canvas in a subroutine whilst my TApplication is defined in main and I have placed the mainApp.Run() at the very end of my main function.
Do I need to call any specific functions after drawing the Canvas to effectively “close” the “action” (i.e. drawing of the histogram) that has just been performed on it?
If the original code works and not your own version, it means that you do something wrong. But I cannot really help without seeing the code (and trying to guess may take time )
Is the original code (the solution I sent) working properly?
It works provided that I do not include any code between drawing the Canvas and the mainApp.Run(). Does that mean that I need to include a mainApp.Run() after each Canvas I draw?