问题
I'm debugging a 3rd party Python script that implements headless image processing with the VTK library. When run with a regular X window session, it works as expected, flashing a window for a split second. When run against Xvfb (virtual framebuffer in memory), it crashes. The script goes like this (fluff omitted):
inname = args[0]
outname = args[1]
from vtk import *
reader = vtkPLYReader()
reader.SetFileName(inname)
gf = vtkGraphicsFactory
gf.SetOffScreenOnlyMode(1)
gf.SetUseMesaClasses(1)
if_ = vtkImagingFactory
if_.SetUseMesaClasses(1)
mapper = vtkPolyDataMapper()
mapper.SetInputConnection(reader.GetOutputPort())
actor = vtkActor()
actor.SetMapper(mapper)
renderer = vtkRenderer()
renderWindow = vtkRenderWindow()
renderWindow.SetSize(xsize, ysize)
renderWindow.SetOffScreenRendering(1)
renderWindow.AddRenderer(renderer)
renderer.AddActor(actor)
renderer.SetBackground(1, 1, 1)
renderWindow.Render() #<------------ This line crashes
wif = vtkWindowToImageFilter()
wif.SetInput(renderWindow)
wif.Update()
writer = vtkPNGWriter()
writer.SetFileName(outname)
writer.SetInput(wif.GetOutput())
writer.Write()
The crash message goes:
ERROR: In /builddir/build/BUILD/VTK/Rendering/vtkXOpenGLRenderWindow.cxx, line 404
vtkXOpenGLRenderWindow (0x26942e0): Could not find a decent visual
Segmentation fault (core dumped)
Xvfb runs as a service; its command line is:
/usr/bin/Xvfb :99 -ac -extension GLX
DISPLAY
is set for :99
for the testing. The OS is RHEL 6.
Any comments what's a "visual" and how do I enable one in Xvfb are welcome.
EDIT: Running glxinfo
gives a similar message:
Error: couldn't find RGB GLX visual or fbconfig
But the GLX extension is right there in the command line. The Xvfb log doesn't have any error messages.
EDIT2: but when I do xdpyinfo -queryExtensions
, GLX is not listed.
回答1:
I use Xvfb to run selenium tests, but I use the module xvfbwrapper, it's a lightweight module for Xvfb
Below the code:
from xvfbwrapper import Xvfb
display = Xvfb()
display.start()
[ yourcode ]
display.stop()
来源:https://stackoverflow.com/questions/21141212/vtk-works-with-real-x-crashes-with-xvfb