Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Segmentation fault on Mac with PyQt5 #316

Open
MrCheatak opened this issue Feb 14, 2023 · 2 comments
Open

Segmentation fault on Mac with PyQt5 #316

MrCheatak opened this issue Feb 14, 2023 · 2 comments
Labels
bug Something isn't working

Comments

@MrCheatak
Copy link

Describe the bug, what's wrong, and what you expected.

Segmentation fault happens after closing the Plotter window, when it's called from a PyQt5 application.
Apparently, it happens upon returning to the PyQt application event loop when garbage collection occurs, because the line 'x=0' executes fine.
I have tried running the example with earlier versions of Pyvista and at version 0.36.0 the SIGSEGV doesn't happen.

Steps to reproduce the bug.

Here is a code with minimal PyQt5 interface with a button.
Clicking the button and closing the window with the Sphere should cause SIGSEGV.

import sys
import pyvista as pv

from PyQt5.QtCore import QSize, Qt
from PyQt5.QtWidgets import QApplication, QMainWindow, QPushButton

def show_pyvista_example():
    pv.Sphere().plot()

class MainWindow(QMainWindow):
    def __init__(self):
        super().__init__()

        self.setWindowTitle("My App")
        self.button = QPushButton("Press Me!")


        # Set the central widget of the Window.
        self.setCentralWidget(self.button)
        self.button.clicked.connect(self.show_sphere)

    def show_sphere(self):
        show_pyvista_example()
        x = 0
        return 1

app = QApplication(sys.argv)

window = MainWindow()
window.show()

app.exec()

System Information

--------------------------------------------------------------------------------
  Date: Tue Feb 14 14:04:45 2023 CET
                OS : Darwin
            CPU(s) : 8
           Machine : x86_64
      Architecture : 64bit
       Environment : Python
        GPU Vendor : NVIDIA Corporation
      GPU Renderer : NVIDIA GeForce GT 650M OpenGL Engine
       GPU Version : 4.1 NVIDIA-14.0.32 355.11.11.10.10.143
  Python 3.10.5 (v3.10.5:f377153967, Jun  6 2022, 12:36:10) [Clang 13.0.0
  (clang-1300.0.29.30)]
           pyvista : 0.38.2
               vtk : 9.2.5
             numpy : 1.22.4
           imageio : 2.25.0
            scooby : 0.7.1
             pooch : v1.6.0
        matplotlib : 3.6.3
             PyQt5 : 5.15.9
              tqdm : 4.64.1
--------------------------------------------------------------------------------

Screenshots

No response

@MrCheatak MrCheatak added the bug Something isn't working label Feb 14, 2023
@banesullivan banesullivan transferred this issue from pyvista/pyvista Feb 14, 2023
@larsoner
Copy link
Contributor

You haven't used pyvistaqt at all to do this plotting but rather pyvista. So this is either a pyvista bug or -- I would probably argue -- a usage bug where if you want to use pyvista + Qt you should use pyvistaqt.BackgroundPlotter not pyvista.Plotter. Can you try incorporating BackgroundPlotter and adding your sphere to it instead of using pv.Sphere.plot() (which will create a pyvista.Plotter)?

@MrCheatak
Copy link
Author

I have managed to incorporate BackgroundPlotter like it is shown below.
Although, does it mean that the pyvista + Qt support is dropped?

  import sys
  import pyvista as pv
  import pyvistaqt as pvqt
  import numpy as np
  
  from PyQt5.QtWidgets import QApplication, QMainWindow, QPushButton
  
  
  class MainWindow(QMainWindow):
      def __init__(self):
          super().__init__()
  
          self.setWindowTitle("My App")
          self.button1 = QPushButton("Press Me!")
  
          # Set the central widget of the Window.
          self.setCentralWidget(self.button1)
  
          self.button1.clicked.connect(self.show_pvqt)
  
      def show_pvqt(self):
          plotter = self.plotter = pvqt.BackgroundPlotter()
          sphere = pv.Sphere()
  
          # Create a plotter window
          self.mesh = plotter.add_mesh(sphere, show_edges=True, name='sphere')
  
          # Customize the color map
          plotter.add_scalar_bar(title="Color Map")
          plotter.add_callback(self.change_color, 100)
  
          # Display the plotter window
          plotter.show()
          x = 0
          return 1
  
      def change_color(self):
          self.plotter.remove_actor('sphere')
          sphere = pv.Sphere()
          colors = np.random.rand(sphere.n_points, 3)
          self.mesh = self.plotter.add_mesh(sphere, scalars=colors, show_edges=True, name='sphere')
          self.plotter.update()
  
  
  app = QApplication(sys.argv)
  window = MainWindow()
  window.show()
  app.exec()

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants