Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Qt5 Segfaults on window resize #11728

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

Closed
jklymak opened this issue Jul 21, 2018 · 2 comments · Fixed by #11731
Closed

Qt5 Segfaults on window resize #11728

jklymak opened this issue Jul 21, 2018 · 2 comments · Fixed by #11731
Assignees
Labels
GUI: Qt Release critical For bugs that make the library unusable (segfaults, incorrect plots, etc) and major regressions.
Milestone

Comments

@jklymak
Copy link
Member

jklymak commented Jul 21, 2018

Bug report

On my machine using master I can reliably get segfaults using QT5Agg by resizing the window a bunch of times (say order 20). There is no segfault on v2.2.2 Suspect #11712 and/or #8951. (Sorry, not quite sure how to revert those locally to test).

python3.6_2018-07-21-150850_JMKMBP.crash.zip

import matplotlib.pyplot as plt
fig, ax = plt.subplots()
plt.show()

Matplotlib version

  • Operating system: macOS 10.13.6
  • Matplotlib version: master as of this AM.
  • Matplotlib backend (print(matplotlib.get_backend())): Qt5Agg
  • Python version: 3.6.3
@jklymak jklymak added this to the v3.0 milestone Jul 21, 2018
@jklymak jklymak added Release critical For bugs that make the library unusable (segfaults, incorrect plots, etc) and major regressions. GUI: Qt labels Jul 21, 2018
@anntzer
Copy link
Contributor

anntzer commented Jul 21, 2018

Does

diff --git a/lib/matplotlib/backends/backend_qt5agg.py b/lib/matplotlib/backends/backend_qt5agg.py
index 6e0e964a8..b009187a4 100644
--- a/lib/matplotlib/backends/backend_qt5agg.py
+++ b/lib/matplotlib/backends/backend_qt5agg.py
@@ -48,10 +48,9 @@ class FigureCanvasQTAgg(FigureCanvasAgg, FigureCanvasQT):
             [[left, self.renderer.height - (top + height * self._dpi_ratio)],
              [left + width * self._dpi_ratio, self.renderer.height - top]])
         reg = self.copy_from_bbox(bbox)
-        buf = reg.to_string_argb()
+        buf = memoryview(reg)
         qimage = QtGui.QImage(
-            buf, width * self._dpi_ratio, height * self._dpi_ratio,
-            QtGui.QImage.Format_ARGB32)
+            buf, buf.shape[1], buf.shape[0], QtGui.QImage.Format_RGBA8888)
         if hasattr(qimage, 'setDevicePixelRatio'):
             # Not available on Qt4 or some older Qt5.
             qimage.setDevicePixelRatio(self._dpi_ratio)

fix it for you? Basically the problem is that the bbox extents are floats, so there may be an off-by-one difference in rounding to get the image size. Format_RGBA8888 may appear as less efficient but in fact we save a copy by directly taking the underlying renderer buffer in memoryview(reg) so it comes down to the same.

@jklymak
Copy link
Member Author

jklymak commented Jul 21, 2018

Seems to, at least to the extent that I got bored of resizing the window w/ the GUI well past the point where I could make it die w/o that patch...

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
GUI: Qt Release critical For bugs that make the library unusable (segfaults, incorrect plots, etc) and major regressions.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants