From 530307e7ec3ed5aae153a4e06f3c4c723d40a41e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?R=C3=A9mi=20Verschelde?= Date: Wed, 24 Jun 2020 16:57:37 +0200 Subject: [PATCH] Main::cleanup: Move MessageQueue deletion further down where it's safer Partial revert of #15702 which triggered the issue. Fixes #39786. (cherry picked from commit 6480efba45ae467e38955012d67857a4a81b752b) --- main/main.cpp | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/main/main.cpp b/main/main.cpp index 74b53a5435f..fa2668ccc5c 100644 --- a/main/main.cpp +++ b/main/main.cpp @@ -2219,8 +2219,8 @@ void Main::cleanup() { ResourceLoader::remove_custom_loaders(); ResourceSaver::remove_custom_savers(); + // Flush before uninitializing the scene, but delete the MessageQueue as late as possible. message_queue->flush(); - memdelete(message_queue); if (script_debugger) { if (use_debug_profiler) { @@ -2297,6 +2297,10 @@ void Main::cleanup() { OS::get_singleton()->set_restart_on_exit(false, List()); //clear list (uses memory) } + // Now should be safe to delete MessageQueue (famous last words). + message_queue->flush(); + memdelete(message_queue); + unregister_core_driver_types(); unregister_core_types();