1
0
mirror of https://github.com/godotengine/godot.git synced 2025-11-22 15:06:45 +00:00

Added test to avoid saving cyclic scene instancing, fixes #9686

This commit is contained in:
Juan Linietsky
2018-11-27 18:56:31 -03:00
parent f2ae14f309
commit 616b91b498
2 changed files with 23 additions and 1 deletions

View File

@@ -999,6 +999,22 @@ void EditorNode::_save_scene_with_preview(String p_file, int p_idx) {
EditorResourcePreview::get_singleton()->check_for_invalidation(p_file); 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) { void EditorNode::_save_scene(String p_file, int idx) {
Node *scene = editor_data.get_edited_scene_root(idx); Node *scene = editor_data.get_edited_scene_root(idx);
@@ -1009,6 +1025,11 @@ void EditorNode::_save_scene(String p_file, int idx) {
return; 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(); editor_data.apply_changes_in_editors();
_save_default_environment(); _save_default_environment();
@@ -1452,7 +1473,7 @@ void EditorNode::_edit_current() {
bool is_node = current_obj->is_class("Node"); bool is_node = current_obj->is_class("Node");
String editable_warning; //none by default String editable_warning; //none by default
if (is_resource) { if (is_resource) {
Resource *current_res = Object::cast_to<Resource>(current_obj); Resource *current_res = Object::cast_to<Resource>(current_obj);

View File

@@ -445,6 +445,7 @@ private:
void _show_messages(); void _show_messages();
void _vp_resized(); 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_scene(String p_file, int idx = -1);
void _save_all_scenes(); void _save_all_scenes();
int _next_unsaved_scene(bool p_valid_filename, int p_start = 0); int _next_unsaved_scene(bool p_valid_filename, int p_start = 0);