From 616b91b498b332c5cace5ed8324eb818d7eb68d2 Mon Sep 17 00:00:00 2001 From: Juan Linietsky Date: Tue, 27 Nov 2018 18:56:31 -0300 Subject: Added test to avoid saving cyclic scene instancing, fixes #9686 --- editor/editor_node.cpp | 23 ++++++++++++++++++++++- editor/editor_node.h | 1 + 2 files changed, 23 insertions(+), 1 deletion(-) diff --git a/editor/editor_node.cpp b/editor/editor_node.cpp index 8f9c91c008..157dd4d66f 100644 --- a/editor/editor_node.cpp +++ b/editor/editor_node.cpp @@ -999,6 +999,22 @@ void EditorNode::_save_scene_with_preview(String p_file, int p_idx) { EditorResourcePreview::get_singleton()->check_for_invalidation(p_file); } +bool EditorNode::_validate_scene_recursive(const String &p_filename, Node *p_node) { + + for (int i = 0; i < p_node->get_child_count(); i++) { + Node *child = p_node->get_child(i); + if (child->get_filename() == p_filename) { + return true; + } + + if (_validate_scene_recursive(p_filename, child)) { + return true; + } + } + + return false; +} + void EditorNode::_save_scene(String p_file, int idx) { Node *scene = editor_data.get_edited_scene_root(idx); @@ -1009,6 +1025,11 @@ void EditorNode::_save_scene(String p_file, int idx) { return; } + if (scene->get_filename() != String() && _validate_scene_recursive(scene->get_filename(), scene)) { + show_accept(TTR("This scene can't be saved because there is a cyclic instancing inclusion.\nPlease resolve it and then attempt to save again."), TTR("OK")); + return; + } + editor_data.apply_changes_in_editors(); _save_default_environment(); @@ -1452,7 +1473,7 @@ void EditorNode::_edit_current() { bool is_node = current_obj->is_class("Node"); String editable_warning; //none by default - + if (is_resource) { Resource *current_res = Object::cast_to(current_obj); diff --git a/editor/editor_node.h b/editor/editor_node.h index e220daf8a9..3fa762c20b 100644 --- a/editor/editor_node.h +++ b/editor/editor_node.h @@ -445,6 +445,7 @@ private: void _show_messages(); void _vp_resized(); + bool _validate_scene_recursive(const String &p_filename, Node *p_node); void _save_scene(String p_file, int idx = -1); void _save_all_scenes(); int _next_unsaved_scene(bool p_valid_filename, int p_start = 0); -- cgit v1.2.3