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
Fix QtInteractor and BackgroundPlotter issues #603
Conversation
#548 changed the inheritance of render window interactor through the new |
79ab560
to
32d14bb
Compare
Codecov Report
@@ Coverage Diff @@
## master #603 +/- ##
==========================================
+ Coverage 83.91% 85.42% +1.51%
==========================================
Files 32 32
Lines 9074 10274 +1200
==========================================
+ Hits 7614 8777 +1163
- Misses 1460 1497 +37 |
import faulthandler
faulthandler.enable()
import pyvista as pv
mesh = pv.Sphere()
p = pv.BackgroundPlotter()
p.add_mesh(mesh)
p.enable_cell_picking(through=True, start=True) results in the following traceback
So it appears that the callback of the picker is triggering a modified event on the renderer which then triggers the |
c08237f
to
4d9dd0f
Compare
Core API is failing unit tests. Could you review and potentially merge #611 and then merge with master? Will make unit testing easier. |
Okay, a hacky conditional decorator was added to thread the render call on Mac and not on Windows/Linux. I've tested this on my Mac and on my Linux VM. I'm going to see if my Windows VM still works and see if all is good there. |
Okay, nevermind. this still has some serious issues. |
The whole point of #293 |
I left in:
And menu exits work fine. However, pressing "q" still causes segfaults more often than not. This is despite the fact that both self.add_key_event("q", lambda: self.app_window.close()) There are still issues. This is the same as the file_menu.addAction('Exit', self.app_window.close) The only thing I can think is that there's something funky going on with how vtk handles the key events and that it doesn't play well with pyqt. To fix this, I added in @threaded
def close(self):
"""Close the plotter.
This function closes the window which in turn will
close the plotter through `signal_close`.
"""
self.app_window.close() With this, I can't get it to segfault/crash/freeze while closing with "q" or the menu or by hand. I think vtk calls need to be threaded so they don't interfere with the main |
The Azure gods seem to be pleased. @banesullivan, @GuillaumeFavelier, since this seems sensitive to the environment, could you please pull and test? |
All good on my end and thanks for the |
This is good to know especially for |
Actually, in my closed source gui, just about all calls to vtk are threaded. This lets me update the plotter in the background, doesn't make the gui freeze when called, and ensures errors (if not caught, and there's a wrapper for that too), will just kill the child thread and not the main one with a ugly segfault. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks all for the great team effort. This was not an easy PR.
So uh... the All else works excellently though |
It probably does the opposite this time: closes the interactor but not the window. That's why there was 2 versions of close before |
Reference to: #388 |
I think the q-key should be connected to |
Co-Authored-By: Simon Frei <freisim93@gmail.com>
Co-Authored-By: Simon Frei <freisim93@gmail.com>
pyvista/pyvista/plotting/qt_plotting.py Lines 739 to 760 in 71dc915
|
I can confirm that calling the action stored in the file menu from the vtk event handler leads to the same segfault. I don't think we can safely have |
@banesullivan, please try it now. Seems that removing |
All good now! I'm going to do one final peruse through the diff and then merge! |
I'm not very enthusiastic with the current situation: Now the pyvista/pyvista/plotting/qt_plotting.py Lines 859 to 867 in c996bac
I can only advice that we test thoroughly all the events that close
With the current state of the code, I get the exact same segfault I had in #603 (comment) with I would be okay to disable temporarily the |
I can reproduce this segfault consistently with any version of
I can mitigate by using
|
Me neither. I found that @GuillaumeFavelier you mind creating a new branch that addresses |
I'll do my best! My first priority right now would be to drastically improve the testing of pyvista so that those issues are detected sooner in the development cycle to avoid regression. I'll try to push in this direction at least. |
#548 introduced issues with threading between VTK and PyQt. These changes fix those issues and attempt to address #600
Detail
BasePlotter.close()
was being called multiple times. It should only be called once.Modified
callback when moving the camera (this one was on me) and calling Modified on the Renderer anytime the camera's position is set (not moved interactively)q
key on theBackgroundPlotter
it was totally messed up and even these changes aren't great... I get random segfaults that crash the kernel from time to time with this (but not every time so this is better). Its mostly mitigated.render
call for theQtInteractor
class - this was the cause of the segfaults happening during cell picking and other times where VTK modified the renderer.__init__
of PyVista to yield tracebacks when segfaults occur (I believefaulthandler
is a standard lib package, but I put it in atry
statement just in case)Renderer
and its camera when closing_first_time
flag is set to false after creating theQtInteractor
to make sure render calls aren't blocked (relevant to Interacting with QT : Graphics are not displaying until clicking on graph area pyvista-support#86)auto_update
to take float time interval for update rate