From 69e5e582c82ec80fbc0da34be3cb3702244474d3 Mon Sep 17 00:00:00 2001 From: ajreckof Date: Wed, 13 Mar 2024 15:35:23 +0100 Subject: [PATCH] fix error where update wouldn't reconnect the signal it should have reconnected and led to errors and crash --- editor/editor_data.cpp | 8 ++++++-- editor/editor_node.cpp | 16 ++++++++-------- 2 files changed, 14 insertions(+), 10 deletions(-) diff --git a/editor/editor_data.cpp b/editor/editor_data.cpp index 47642c15926..4b68a21cb98 100644 --- a/editor/editor_data.cpp +++ b/editor/editor_data.cpp @@ -721,8 +721,12 @@ bool EditorData::check_and_update_scene(int p_idx) { } new_scene->set_scene_file_path(edited_scene[p_idx].root->get_scene_file_path()); - - memdelete(edited_scene[p_idx].root); + Node *old_root = edited_scene[p_idx].root; + for (int i = 0; i < old_root->get_child_count(); i++) { + memdelete(old_root->get_child(i)); + } + old_root->replace_by(new_scene); + memdelete(old_root); edited_scene.write[p_idx].root = new_scene; if (!new_scene->get_scene_file_path().is_empty()) { edited_scene.write[p_idx].path = new_scene->get_scene_file_path(); diff --git a/editor/editor_node.cpp b/editor/editor_node.cpp index 89e5e3f3b07..7ca3b49c25f 100644 --- a/editor/editor_node.cpp +++ b/editor/editor_node.cpp @@ -3790,14 +3790,6 @@ void EditorNode::_set_current_scene_nocheck(int p_idx) { editor_folding.save_scene_folding(editor_data.get_edited_scene_root(p_idx), editor_data.get_scene_path(p_idx)); } - if (editor_data.check_and_update_scene(p_idx)) { - if (editor_data.get_scene_path(p_idx) != "") { - editor_folding.load_scene_folding(editor_data.get_edited_scene_root(p_idx), editor_data.get_scene_path(p_idx)); - } - - EditorUndoRedoManager::get_singleton()->clear_history(false, editor_data.get_scene_history_id(p_idx)); - } - changing_scene = true; editor_data.save_edited_scene_state(editor_selection, &editor_history, _get_main_scene_state()); @@ -3836,6 +3828,14 @@ void EditorNode::_set_current_scene_nocheck(int p_idx) { if (tabs_to_close.is_empty()) { callable_mp(this, &EditorNode::_set_main_scene_state).call_deferred(state, get_edited_scene()); // Do after everything else is done setting up. } + + if (editor_data.check_and_update_scene(p_idx)) { + if (!editor_data.get_scene_path(p_idx).is_empty()) { + editor_folding.load_scene_folding(editor_data.get_edited_scene_root(p_idx), editor_data.get_scene_path(p_idx)); + } + + EditorUndoRedoManager::get_singleton()->clear_history(false, editor_data.get_scene_history_id(p_idx)); + } } void EditorNode::setup_color_picker(ColorPicker *p_picker) {