Title: [Bug]: FigureCanvasQT is seemingly prematurely freed under certain conditions · Issue #29618 · matplotlib/matplotlib · GitHub
Open Graph Title: [Bug]: FigureCanvasQT is seemingly prematurely freed under certain conditions · Issue #29618 · matplotlib/matplotlib
X Title: [Bug]: FigureCanvasQT is seemingly prematurely freed under certain conditions · Issue #29618 · matplotlib/matplotlib
Description: Bug summary I'm in the process of updating some code using matplotlib and pyside6. Using version 6.6.0 of PySide there is no error, but on versions 6.7.0 and newer I get an error indicating that the underlying C++ object has been prematu...
Open Graph Description: Bug summary I'm in the process of updating some code using matplotlib and pyside6. Using version 6.6.0 of PySide there is no error, but on versions 6.7.0 and newer I get an error indicating that th...
X Description: Bug summary I'm in the process of updating some code using matplotlib and pyside6. Using version 6.6.0 of PySide there is no error, but on versions 6.7.0 and newer I get an error indicating tha...
Opengraph URL: https://github.com/matplotlib/matplotlib/issues/29618
X: @github
Domain: github.com
{"@context":"https://schema.org","@type":"DiscussionForumPosting","headline":"[Bug]: FigureCanvasQT is seemingly prematurely freed under certain conditions","articleBody":"### Bug summary\n\nI'm in the process of updating some code using matplotlib and pyside6. Using version 6.6.0 of PySide there is no error, but on versions 6.7.0 and newer I get an error indicating that the underlying C++ object has been prematurely freed. I've had a hard time identifying the source of the bug. I have opened an [issue](https://bugreports.qt.io/browse/PYSIDE-3018) with pyside, but as I have been unable to recreate the bug without matplotlib components I thought I would open an issue here and see if anyone had any ideas. Sorry to bother, and thanks for the help. \n\n\n\n### Code for reproduction\n\n```Python\nfrom PySide6.QtWidgets import QWidget, QMainWindow, QVBoxLayout, QApplication\nfrom matplotlib.backends.backend_qt import FigureCanvasQT\n\nfrom matplotlib.figure import Figure\nclass test_class(QMainWindow):\n def __init__(self, parent):\n super().__init__(parent)\n self.testfig = None\n self.canvas = FigureCanvasQT(self.testfig)\n self.vbox = QWidget(self)\n self.canvas.setParent(self.vbox)\n\ndef test_testing():\n qtbot = QApplication([])\n c1 = test_class(None)\n c1.setVisible(True)\n\ntest_testing()\nQApplication.instance().processEvents()\n```\n\n### Actual outcome\n\nTraceback (most recent call last):\n File \"/home/ez/test.py\", line 20, in \u003cmodule\u003e\n QApplication.instance().processEvents()\n File \"/home/ez/micromamba/envs/pycodas/lib/python3.11/site-packages/matplotlib/backends/backend_qt.py\", line 495, in _draw_idle\n if self.height() \u003c 0 or self.width() \u003c 0:\n ^^^^^^^^^^^^^\nRuntimeError: Internal C++ object (FigureCanvasQT) already deleted.\n\n\n### Expected outcome\n\nIt shouldn't do anything, maybe briefly display a window, but the error is unexpected. I may just be using something wrong, but this code did run in the past without error\n\n### Additional information\n\nI should mention that I copied the entire class definition of `FigureCanvasQT` into my test file and that runs just fine, which I find somewhat confusing. Though this may be explained by the fact that I am using version 3.9.1 of matplotlib which may differ from the main branch. \n\n\n### Operating system\n\nubuntu\n\n### Matplotlib Version\n\n3.9.1\n\n### Matplotlib Backend\n\nqtagg\n\n### Python version\n\n3.11.11\n\n### Jupyter version\n\n_No response_\n\n### Installation\n\nconda","author":{"url":"https://github.com/ezra-varady","@type":"Person","name":"ezra-varady"},"datePublished":"2025-02-14T03:35:30.000Z","interactionStatistic":{"@type":"InteractionCounter","interactionType":"https://schema.org/CommentAction","userInteractionCount":6},"url":"https://github.com/29618/matplotlib/issues/29618"}
| route-pattern | /_view_fragments/issues/show/:user_id/:repository/:id/issue_layout(.:format) |
| route-controller | voltron_issues_fragments |
| route-action | issue_layout |
| fetch-nonce | v2:506f0ea9-ab09-118b-941d-df55143b1473 |
| current-catalog-service-hash | 81bb79d38c15960b92d99bca9288a9108c7a47b18f2423d0f6438c5b7bcd2114 |
| request-id | E152:2FE627:18054B:2029E2:6A527208 |
| html-safe-nonce | 35b6dc8085b15cdff0359ea12fa23862208f9c36a67d1b7eeb0c26e103d723a8 |
| visitor-payload | eyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiJFMTUyOjJGRTYyNzoxODA1NEI6MjAyOUUyOjZBNTI3MjA4IiwidmlzaXRvcl9pZCI6IjM3OTcyNjY4MDUzNTA4ODc5NDQiLCJyZWdpb25fZWRnZSI6ImlhZCIsInJlZ2lvbl9yZW5kZXIiOiJpYWQifQ== |
| visitor-hmac | d7a412c6136eeb4569690b360bef08d3dc9d79d6880dc3aa7b2b058bbbc62964 |
| hovercard-subject-tag | issue:2852587146 |
| github-keyboard-shortcuts | repository,issues,copilot |
| google-site-verification | Apib7-x98H0j5cPqHWwSMm6dNU4GmODRoqxLiDzdx9I |
| octolytics-url | https://collector.github.com/github/collect |
| analytics-location | / |
| fb:app_id | 1401488693436528 |
| apple-itunes-app | app-id=1477376905, app-argument=https://github.com/_view_fragments/issues/show/matplotlib/matplotlib/29618/issue_layout |
| twitter:image | https://opengraph.githubassets.com/a4af2e749bdb683d813834eb10bf103933aa12934be2e2e7d89736f7ec8f3de0/matplotlib/matplotlib/issues/29618 |
| twitter:card | summary_large_image |
| og:image | https://opengraph.githubassets.com/a4af2e749bdb683d813834eb10bf103933aa12934be2e2e7d89736f7ec8f3de0/matplotlib/matplotlib/issues/29618 |
| og:image:alt | Bug summary I'm in the process of updating some code using matplotlib and pyside6. Using version 6.6.0 of PySide there is no error, but on versions 6.7.0 and newer I get an error indicating that th... |
| og:image:width | 1200 |
| og:image:height | 600 |
| og:site_name | GitHub |
| og:type | object |
| og:author:username | ezra-varady |
| hostname | github.com |
| expected-hostname | github.com |
| None | b9a586c06a05a7a86fc7e3f4dbd03e42f6869085879aa184aa6369456dbd50fb |
| turbo-cache-control | no-preview |
| go-import | github.com/matplotlib/matplotlib git https://github.com/matplotlib/matplotlib.git |
| octolytics-dimension-user_id | 215947 |
| octolytics-dimension-user_login | matplotlib |
| octolytics-dimension-repository_id | 1385122 |
| octolytics-dimension-repository_nwo | matplotlib/matplotlib |
| octolytics-dimension-repository_public | true |
| octolytics-dimension-repository_is_fork | false |
| octolytics-dimension-repository_network_root_id | 1385122 |
| octolytics-dimension-repository_network_root_nwo | matplotlib/matplotlib |
| turbo-body-classes | logged-out env-production page-responsive |
| disable-turbo | false |
| browser-stats-url | https://api.github.com/_private/browser/stats |
| browser-errors-url | https://api.github.com/_private/browser/errors |
| release | 07a982c1d40157c619b364352b704c3ce66bb332 |
| ui-target | full |
| theme-color | #1e2327 |
| color-scheme | light dark |
Links:
Viewport: width=device-width