Issue with TCanvas and visual studio 2008

Hi there,

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!

// 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.);

// Prepare the random number generator.

// 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) );
if ( i%100 == 0 ) {

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.


Many thanks. That’s what I thought too. Could it be some compiler option which prevents the Canvas from appearing?

unlikely, but difficult to say without seeing your application.
Do you see the problem with the piece of code that you posted?


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?

Thanks again.


Further to my previous message - I just came across 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?

Any input much appreciated.

Hi Wolf,

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.

Cheers, Bertrand.
wolfschu.tar.gz (3.32 KB)

Many thanks, Bertrand.

The compilation worked fine. However when I run the code, no Canvas appears and I get the following error:

Unhandled exception at 0x100750bd in wolfschu.exe: 0xC0000005: Access violation reading location 0x00000090. This happens when it reaches the line


Would you know what this may be due to?

Thanks very much again,

Hi Wolf,

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?

Cheers, Bertrand.

Hi Bertrand,

Many thanks for your reply.

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?


Hi Wolf,

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.

Cheers, Bertrand.

Hi Bertrand,

I have downloaded the root_v5.24.00.win32.vc90.msi version…

Many thanks.

Further to my previous email, here are the details of the error message I get from VS2008:

[Frames below may be incorrect and/or missing, no symbols loaded for libCore.dll]	

wolfschu.exe!main(int argc=0, char * * argv=0x7efde000) Line 34 + 0x14 bytes C++


Hi Wolf,

I don’t see any problem with the solution and ROOT v5.24.00.
Then my next questions are:

  • Is ROOT working properly? Are you able to execute the macros in the $ROOTSYS/tutorials directory?
  • Are you able to build and run the applications in $ROOTSYS/test directory (by typing “nmake -f Makefile.win32” into this directory)?

Cheers, Bertrand.

Hi Bertrand,

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?

Thanks very much,

Hi Wolf,

If you read the instructions for Windows on this page:
There are a few informations that may be useful… :wink:

Important installation notes:

  • Do not untar in a directory with a name containing blank characters.
    And as previously said, try the root macros in tutorials first, to be sure everything works correctly.

Cheers, Bertrand.

Many thanks, Bertrand. That actually has solved the initial problem of getting the Canvas to appear. :slight_smile:

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?

Many thanks again.

Hi Wolf,

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 :wink:)
Is the original code (the solution I sent) working properly?

Cheers, Bertrand.

Hi Bertrand,

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?


Further to my previous message, would it be possible to place the TApplication mainApp(“mainApp”, &argc, argv); inside a function other than main?

Many thanks.