summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJuan Linietsky <reduzio@gmail.com>2018-11-27 18:56:31 -0300
committerJuan Linietsky <reduzio@gmail.com>2018-11-27 18:56:31 -0300
commit616b91b498b332c5cace5ed8324eb818d7eb68d2 (patch)
tree8e60c9a4e5368e06a888b40258fd3cc1bc34197d
parentf2ae14f3097c025382bd8645748f1d8b85560a2e (diff)
Added test to avoid saving cyclic scene instancing, fixes #9686
-rw-r--r--editor/editor_node.cpp23
-rw-r--r--editor/editor_node.h1
2 files changed, 23 insertions, 1 deletions
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<Resource>(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);