Pyroot and openGl mode trouble


I have problem with Pyroot and opengl mode. Once created, I cannot interact with a graph (or histogram created with opengl).
To show the problem, here is a modified scipt from tutorials/pyroot.
The equivalent, using CINT, works without a problem

I am using ROOT 5.26/00 compiled with GCC 4.1.2, Python 2.4.4 and Mesa 6.5.1


from ROOT import TCanvas, TPaveText, TPad, TF2
from ROOT import gROOT, gStyle

#c1 = TCanvas( 'c1', 'Surfaces Drawing Options', 200, 10, 700, 900 )
c1 = TCanvas( 'glc1', 'Surfaces Drawing Options', 200, 10, 700, 900 )

c1.SetFillColor( 42 )
gStyle.SetFrameFillColor( 42 )
title = TPaveText( .2, 0.96, .8, .995 )
title.SetFillColor( 33 )
title.AddText( 'Examples of Surface options' )

pad1 = TPad( 'pad1', 'Gouraud shading', 0.03, 0.50, 0.98, 0.95, 21 )
pad2 = TPad( 'pad2', 'Color mesh',      0.03, 0.02, 0.98, 0.48, 21 )

# We generate a 2-D function
f2 = TF2( 'f2', 'x**2 + y**2 - x**3 -8*x*y**4', -1, 1.2, -1.5, 1.5 )
f2.SetContour( 48 )
f2.SetFillColor( 45 )

# Draw this function in pad1 with Gouraud shading option
pad1.SetPhi( -80 )
#f2.Draw( 'surf4' )
f2.Draw( 'glsurf4' )

# Draw this function in pad2 with color mesh option
pad2.SetTheta( 25 )
pad2.SetPhi( -110 )
#f2.Draw( 'surf1' )
f2.Draw( 'glsurf1' )



there appears to be a startup problem with the threads that feed GUI events. Depending on which one is first, the code GL canvas does or does not receive events. Beats me why.

To make the main thread wait for the GUI thread to start up, you can add at the top of your script:import ROOT ROOT.PyConfig.GUIThreadScheduleOnce += [ lambda : 1 ]
Or, defer the creation of the TCanvas.

If either of these “solutions” sound like hacks, that’d be so, but I’m not seeing what is going wrong …


P.S. I get this error when running the script, although the display is fine:
Error in TGLLevelPalette::GeneratePalette: Number of contours 20 is too big for GL 1D texture, try to reduce it to 0
Error in TGLLevelPalette::GeneratePalette: Number of contours 20 is too big for GL 1D texture, try to reduce it to 0

Hi Wim

I tried what you wrote but without success. My Canvas still doesn’t receive any signal :frowning: . And yes, I startes my script with those 2 lines.

Any other suggestion?


Any other suggestion?

not sure … various ways of changing the timing, but none of those address the underlying cause (which I haven’t figured out yet).



at issue is the call to c1.Update(). It will tickle the initialization of OpenGL (if not already done) with the GL device thus created on the main thread, it doesn’t respond to updates from the GUI thread and hence the objects can not be moved.

With the timing somewhat different (as happened by playing with some extra lines here and there like I suggested above, or by running under gdb) the TCanvas::Update() happens under the GUI thread and all is fine.

Of course, to make things easy :confused: , the start of the GUI thread can also come too early, leaving OpenGL not completely initialized, and then you get messages like I posted above (or worse).

There are two options: run gSystem.ProcessEvents on the main thread (which does mean loosing the prompt); or have the first c1.Draw or c1.Update done on the GUI thread, like so:

import ROOT ROOT.PyConfig.GUIThreadScheduleOnce += [ c1.Update ] ROOT.PyGUIThread.join(0.1) instead of c1.Update() in the script. (Put this after all other Draw()s to prevent error messages like above about number of contours etc.)