From e8d31cc765d520802c425965ebb4f2eeb220dce7 Mon Sep 17 00:00:00 2001 From: Juan Linietsky Date: Thu, 17 Jan 2019 09:09:01 -0300 Subject: Perform a cleaner exit for resource preview, fixes #24206 --- editor/editor_node.cpp | 17 +++++++++++------ editor/editor_node.h | 2 ++ editor/editor_resource_preview.cpp | 15 +++++++++++---- editor/editor_resource_preview.h | 2 ++ 4 files changed, 26 insertions(+), 10 deletions(-) (limited to 'editor') diff --git a/editor/editor_node.cpp b/editor/editor_node.cpp index 9169227e8a..719130621e 100644 --- a/editor/editor_node.cpp +++ b/editor/editor_node.cpp @@ -494,7 +494,7 @@ void EditorNode::_fs_changed() { } } - get_tree()->quit(); + _exit_editor(); } } @@ -1120,7 +1120,7 @@ void EditorNode::save_all_scenes_and_restart() { to_reopen = get_tree()->get_edited_scene_root()->get_filename(); } - get_tree()->quit(); + _exit_editor(); String exec = OS::get_singleton()->get_executable_path(); List args; @@ -2356,6 +2356,12 @@ int EditorNode::_next_unsaved_scene(bool p_valid_filename, int p_start) { return -1; } +void EditorNode::_exit_editor() { + exiting = true; + resource_preview->stop(); //stop early to avoid crashes + get_tree()->quit(); +} + void EditorNode::_discard_changes(const String &p_str) { switch (current_option) { @@ -2383,14 +2389,13 @@ void EditorNode::_discard_changes(const String &p_str) { case FILE_QUIT: { _menu_option_confirm(RUN_STOP, true); - exiting = true; - get_tree()->quit(); + _exit_editor(); + } break; case RUN_PROJECT_MANAGER: { _menu_option_confirm(RUN_STOP, true); - exiting = true; - get_tree()->quit(); + _exit_editor(); String exec = OS::get_singleton()->get_executable_path(); List args; diff --git a/editor/editor_node.h b/editor/editor_node.h index d7d969fb16..13bebea5f0 100644 --- a/editor/editor_node.h +++ b/editor/editor_node.h @@ -470,6 +470,8 @@ private: void _dropped_files(const Vector &p_files, int p_screen); String _recent_scene; + void _exit_editor(); + bool convert_old; void _unhandled_input(const Ref &p_event); diff --git a/editor/editor_resource_preview.cpp b/editor/editor_resource_preview.cpp index 25139b0163..368efbc48f 100644 --- a/editor/editor_resource_preview.cpp +++ b/editor/editor_resource_preview.cpp @@ -416,6 +416,16 @@ void EditorResourcePreview::check_for_invalidation(const String &p_path) { } } +void EditorResourcePreview::stop() { + if (thread) { + exit = true; + preview_sem->post(); + Thread::wait_to_finish(thread); + memdelete(thread); + thread = NULL; + } +} + EditorResourcePreview::EditorResourcePreview() { singleton = this; preview_mutex = Mutex::create(); @@ -428,10 +438,7 @@ EditorResourcePreview::EditorResourcePreview() { EditorResourcePreview::~EditorResourcePreview() { - exit = true; - preview_sem->post(); - Thread::wait_to_finish(thread); - memdelete(thread); + stop(); memdelete(preview_mutex); memdelete(preview_sem); } diff --git a/editor/editor_resource_preview.h b/editor/editor_resource_preview.h index 055ecc6bbf..85ac78d58f 100644 --- a/editor/editor_resource_preview.h +++ b/editor/editor_resource_preview.h @@ -126,6 +126,8 @@ public: void remove_preview_generator(const Ref &p_generator); void check_for_invalidation(const String &p_path); + void stop(); + EditorResourcePreview(); ~EditorResourcePreview(); }; -- cgit v1.2.3