From 509e0a9811f789acbff8a6843a3f6b9d9e0e7ef6 Mon Sep 17 00:00:00 2001 From: Damien Elmes Date: Sat, 3 Dec 2022 19:33:51 +1000 Subject: [PATCH] Try to address crashes on shutdown I was able to reproduce the crashes fairly reliably by opening the prefs screen on startup and shutting down the app after 600ms; after this change the crashes no longer seem to occur. --- qt/aqt/main.py | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/qt/aqt/main.py b/qt/aqt/main.py index 976471d9c..579c75cf4 100644 --- a/qt/aqt/main.py +++ b/qt/aqt/main.py @@ -519,7 +519,16 @@ class AnkiQt(QMainWindow): self.mediaServer.shutdown() # Rust background jobs are not awaited implicitly self.backend.await_backup_completion() - self.app.exit(0) + self.deleteLater() + app = self.app + + def exit(): + # try to ensure Qt objects are deleted in a logical order, + # to prevent crashes on shutdown + gc.collect() + app.exit(0) + + self.progress.single_shot(100, exit, False) # Sound/video ##########################################################################