Details
-
Bug
-
Resolution: Won't Do
-
Not Evaluated
-
None
-
5.15.0
-
None
-
Python 3.8.5, Ubuntu 20.04
Description
I like the QGraphicsScene feature, but I've run into a problem.
I'm trying to create items to add to a QGraphicsScene, and I want them to respond to hover events. I made them raise events back to the main widget that owns the QGraphicsScene, but I suspect that reference cycle is causing problems.
I don't see any problems when I run the main program, but I do see it when I run a bunch of unit tests that are creating widgets and tearing them down, so I guess either there's a bug in the reference handling, or I'm missing a clean up step.
Here's an example script that reproduces the SIGSEGV by repeatedly creating and releasing a widget with a QGraphicsScene.
from PySide2.QtWidgets import QApplication, QWidget, QVBoxLayout, \ QGraphicsView, QGraphicsScene, QGraphicsEllipseItem class MyDisplay(QWidget): def __init__(self): super().__init__() layout = QVBoxLayout(self) self.view = view = QGraphicsView() layout.addWidget(view) scene = QGraphicsScene(0, 0, 200, 200) view.setScene(scene) piece = QGraphicsEllipseItem(0, 0, 100, 100) piece.foo = self scene.addItem(piece) def main(): app = QApplication() n = 100 # Anything higher than 21 triggers a SIGSEGV on my laptop. is_tidy = False # False triggers SIGSEGV, True doesn't. for i in range(n): display = MyDisplay() if is_tidy: display.view.scene().clear() main()
If I don't explicitly clear the QGraphicsScene, I get the SIGSEGV. I don't see anything in the QGraphicsScene documentation that says I have to call clear(), though. Is that really needed, or is this a bug?