TCanvas, how to store and restore preserving size

Dear rooters,
Running root_v5.25.02 on Ubuntu 9.10, 64 bit
Intel® Core™2 Duo CPU T9600 @ 2.80GHz

I want to store a TCanvas in a root file and restore it preserving its size.
The canvas has toolbar and editor.
I add a macro twrite.cxx which writes the canvas. It has an optional
sleep after removing editor and toolbar.
Running it with sleep=1 I get as expected:

canw, canh 600 600                                                   
winw, winh 604 628                                                   
sleep 2 secs                                                         
canw, canh 600 600                                                   
winw, winh 604 628                                                   
bits: 3030008                                                        

Without sleep I get:

canw, canh 600 600                                                   
winw, winh 604 628                                                   
dont sleep                                                           
canw, canh 600 600
winw, winh 779 658
bits: 3030008

Note the unexpected window width and height!!
I also attach a tread.cxx which confirms the unexpected result.

Do I see a phantom or is it real.

tread.cxx (1 KB)
twrite.cxx (1.32 KB)

Hi Otto,

This is maybe due to a X11 latency when updating/querying the values…
To solve the problem, just force the update, by adding two lines, as shown below:

cout << "dont sleep" << endl; fCanvas->GetCanvasImp()->ForceUpdate(); // force layout gSystem->ProcessEvents(); // apply update

HI Bertrand,
thanks for the quick help.
Otto :smiley: