tpaviot / pythonocc-core

Python package for 3D geometry CAD/BIM/CAM
GNU Lesser General Public License v3.0
1.38k stars 380 forks source link

init_display gives Segmentation fault (core dumped) with pythonocct-core 7.7.0 and pyside2 #1217

Open hongyuan1306 opened 1 year ago

hongyuan1306 commented 1 year ago

With the latest pythonocc-core version 7.7.0 and pyside2, init_display() is throwing a Segmentation fault.

The error can be reproduced by running the following on Ubuntu 23.04:

conda create --name=pyoccenv python=3.9
conda activate pyoccenv
conda install -c conda-forge pythonocc-core=7.7.0 pyside2

and running python:

(pyoccenv) hong@hong-office:~/workspace/cnc$ python 
Python 3.9.16 | packaged by conda-forge | (main, Feb  1 2023, 21:39:03)                    
[GCC 11.3.0] on linux                                                                      
Type "help", "copyright", "credits" or "license" for more information.                     
>>> from OCC.Display.SimpleGui import init_display                                         
>>> init_display()
qt-pyside2 backend - Qt version 5.15.8
####### 3D rendering pipe initialisation #####
Display3d class initialization starting ...
Aspect_DisplayConnection created.
OpenGl_GraphicDriver created.
V3d_Viewer created.
AIS_InteractiveContext created.
V3d_View created
Segmentation fault (core dumped)

Running the above procedure on Win11 is OK. And also if I install pyqt5 (using pip) instead of pyside2, there is also no problem.

hongyuan1306 commented 1 year ago

I find that in order to avoid the above segmentation fault, one has to call load_backend before importing init_display:

(cnc) hong@hong-office:~/workspace/cnc$ python
Python 3.10.11 | packaged by conda-forge | (main, May 10 2023, 18:58:44) [GCC 11.3.0] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> from OCC.Display.backend import load_backend
>>> load_backend()
'qt-pyside2'
>>> from OCC.Display.SimpleGui import init_display
>>> init_display()
qt-pyside2 backend - Qt version 5.15.8
####### 3D rendering pipe initialisation #####
Display3d class initialization starting ...
Aspect_DisplayConnection created.
OpenGl_GraphicDriver created.
V3d_Viewer created.
AIS_InteractiveContext created.
V3d_View created
Xw_Window created.
TKOpenGl | Type: Other | ID: 0 | Severity: Medium | Message:
  OpenGl_Window::CreateWindow: window Visual is incomplete: no stencil buffer
Display3d class successfully initialized.
#########################################
...