marcomusy / vedo

A python module for scientific analysis of 3D data based on VTK and Numpy
https://vedo.embl.es
MIT License
2.05k stars 266 forks source link

Segfault upon calling vedo.show on server #1063

Closed ldouteau closed 8 months ago

ldouteau commented 8 months ago

Hi,

I'm currently implementing some reg tests on an application that uses Vedo for visualization purposes. The test is very simple, just trying to make sure that my object gets created properly. I set up Vedo objects, call show (must not be very clever), that's it. Tests run properly on my laptop, both on Windows & WSL2. Using Python 3.11 & Pytest, Vedo 2024.5.1

When i tried to run CI on our Gitlab server, I got a segmentation fault at test collection. For some reason, upon collecting tests that include a vedo.show, Pytest segfaults immediately. After some testing, running the following piece of code on our sever (Ubuntu 22.04 LTS) generates a segfault, even though it takes a bit longer to get it. Thus my current workaround is to skip these reg tests when running CI.

import vedo

def test_show():
    pts = vedo.Points([[1, 2, 3]])
    vedo.show(pts).close()
    print("success")

if __name__ == "__main__":
    test_show()

The logs I get are below. The visualization libraries (libGL) are installed on the server. As i don't get this failure in other platform i assume it's related to the absence of X11 forwarding or something (I know nothing about it sorry). I tried to track what happens in VTK, but couldn't find a better minimal example.

vedo_test.py Fatal Python error: Segmentation fault

Current thread 0x00007f87749e7000 (most recent call first):
  File "~/vedo_test/.venv/lib/python3.10/site-packages/vedo/plotter.py", line 892 in initialize_interactor
  File "~/vedo_test/.venv/lib/python3.10/site-packages/vedo/plotter.py", line 3373 in show
  File "~/vedo_test/.venv/lib/python3.10/site-packages/vedo/plotter.py", line 344 in show

I understand that the procedure i followed has several caveats, from the reg test running show to the server not having display tools. Do you have any improvement to suggest ? I tried to turn off the interactivity of show, but that had no impact. More generally, do you have any suggestion for nice reg tests with Vedo ?

Sorry for the very unprecise question, and happy friday

marcomusy commented 8 months ago

Hi @ldouteau yes - it's related to X11 forwarding have you already had a look at https://vedo.embl.es/autodocs/content/vedo/vedo.html#running-on-a-server ?

From inside a python script you can also call:

import vedo
vedo.settings.start_xvfb()
# vedo.settings.initi_colab()

# ...

Hope this helps!

ldouteau commented 8 months ago

Hi Marco, Thanks for the answer & the reference to the docs, i missed it. It solves the issue i have with segfault at test collection. However, i'm still getting seg faults with the minimal example provided (screenshot of a cube). I tested both the python & bash versions. I get the following log, that is not very helpful. I tested that on Ubuntu 22.04 LTS with Python 3.10 & a fresh new virtual environment

/usr/bin/Xvfb
starting xvfb (can take a minute) ... xvfb started.
Aborted (core dumped)
marcomusy commented 8 months ago

Hi, does this script also crash?

import vtk

cone = vtk.vtkConeSource()

mapper = vtk.vtkPolyDataMapper()
mapper.SetInputConnection(cone.GetOutputPort())

actor = vtk.vtkActor()
actor.SetMapper(mapper)

ren = vtk.vtkRenderer()
ren.AddActor(actor)

renWin = vtk.vtkRenderWindow()
renWin.SetOffScreenRendering(True)
renWin.SetSize(500, 500)
renWin.AddRenderer(ren)
renWin.Render()
ldouteau commented 8 months ago

Hi Marco. Sorry for the late answer. Yes this script crashes too, with the following logs:

2024-03-12 11:57:47.543 (   0.181s) [    7F9ABA305000]vtkXOpenGLRenderWindow.:456    ERR| vtkXOpenGLRenderWindow (0x56447770bfc0): bad X server connection. DISPLAY=
Aborted (core dumped)
marcomusy commented 8 months ago

Hi, I' afraid then it's a problem with the server not starting.. unrelated to vedo. I would manually check on your server the individual steps in https://github.com/marcomusy/vedo/blob/9e68ef2a7ae7f3632067590319875fcf9fce9ebc/vedo/settings.py#L728

ldouteau commented 8 months ago

Ok, that's kind of what i expected when i tested your suggestion earlier today. As it's not critical for me i guess i won't investigate more on this. Thanks for your efficient support, as usual !