Commit 36433708 authored by Luke Campagnola's avatar Luke Campagnola
Browse files

Added workaround for Qt crash-at-exit bug (make sure that all GraphicsItems...

Added workaround for Qt crash-at-exit bug (make sure that all GraphicsItems live in a scene before exiting)
parent 6932c341
......@@ -119,10 +119,26 @@ from .SignalProxy import *
from .ptime import time
## Workaround for Qt exit crash:
## ALL QGraphicsItems must have a scene before they are deleted.
## This is potentially very expensive, but preferred over crashing.
import atexit
def cleanup():
if QtGui.QApplication.instance() is None:
return
import gc
s = QtGui.QGraphicsScene()
for o in gc.get_objects():
try:
if isinstance(o, QtGui.QGraphicsItem) and o.scene() is None:
s.addItem(o)
except RuntimeError: ## occurs if a python wrapper no longer has its underlying C++ object
continue
atexit.register(cleanup)
## Convenience functions for command-line use
## Convenience functions for command-line use
plots = []
images = []
......@@ -176,8 +192,8 @@ show = image ## for backward compatibility
def mkQApp():
global QAPP
if QtGui.QApplication.instance() is None:
global QAPP
QAPP = QtGui.QApplication([])
return QAPP
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment