Issue with TCanvas

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!

P.S. Could it be that there is something wrong with the compiler options, preventing the Canvas from appearing?

// 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 ) {

This is a duplicate post. See answers at