Workaround: Before closing the window, remove the global stack

There's an extensive explanation in the documentation. But truth be told, I don't know why the conversion of global stack to QObject fails after the main window is closed. This may be something in PyQt as it doesn't seem to happen for Nallath who is still on PyQt5.11, but did update Qt to 5.14. So this should be considered a workaround.

This is currently just ONE of the reasons why the application crashes on exit in PyQt5.14+. There is another, much more mysterious issue that is causing the application to segfault on exit, which is still happening. But if it didn't happen it would otherwise still crash on this, so this needs to be solved anyway.

Contributes to issue CURA-7813.
This commit is contained in:
Ghostkeeper 2021-03-22 15:55:37 +01:00
parent 2c33ebdd05
commit 93a3f15b4f
No known key found for this signature in database
GPG Key ID: D2A8871EE34EC59A

View File

@ -603,6 +603,15 @@ class CuraApplication(QtApplication):
@pyqtSlot()
def closeApplication(self) -> None:
Logger.log("i", "Close application")
# Workaround: Before closing the window, remove the global stack.
# This is necessary because as the main window gets closed, hundreds of QML elements get updated which often
# request the global stack. However as the Qt-side of the Machine Manager is being dismantled, the conversion of
# the Global Stack to a QObject fails.
# If instead we first take down the global stack, PyQt will just convert `None` to `null` which succeeds, and
# the QML code then gets `null` as the global stack and can deal with that as it deems fit.
self.getMachineManager().setActiveMachine(None)
main_window = self.getMainWindow()
if main_window is not None:
main_window.close()