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!
Wolf

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.);
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();
}
}

This is a duplicate post. See answers at root.cern.ch/phpBB2/viewtopic.php?t=8970