From 92cc7b840eff99e90b64caad6883aefbe4c3dd1e Mon Sep 17 00:00:00 2001 From: Nathan Warden Date: Mon, 19 Jan 2015 15:47:50 -0500 Subject: Fixed a bug where a user could add a cyclical dependency, causing a crash. --- tools/editor/scene_tree_dock.cpp | 29 ++++++++++++++++++++++++++++- 1 file changed, 28 insertions(+), 1 deletion(-) (limited to 'tools/editor/scene_tree_dock.cpp') diff --git a/tools/editor/scene_tree_dock.cpp b/tools/editor/scene_tree_dock.cpp index cff3913579..d8d713ee40 100644 --- a/tools/editor/scene_tree_dock.cpp +++ b/tools/editor/scene_tree_dock.cpp @@ -79,7 +79,15 @@ Node* SceneTreeDock::instance(const String& p_file) { //accept->get_cancel()->hide(); accept->get_ok()->set_text("Ugh"); accept->set_text(String("Error loading scene from ")+p_file); - accept->popup_centered(Size2(300,70));; + accept->popup_centered(Size2(300,70)); + return NULL; + } + + if (_cyclical_dependency_exists(edited_scene->get_filename(), instanced_scene)) { + + accept->get_ok()->set_text("Ok"); + accept->set_text(String("Cannot instance the scene '")+p_file+String("' because the current scene exists within one of its' nodes.")); + accept->popup_centered(Size2(300,90)); return NULL; } @@ -100,6 +108,25 @@ Node* SceneTreeDock::instance(const String& p_file) { } +bool SceneTreeDock::_cyclical_dependency_exists(const String& p_target_scene_path, Node* p_desired_node) { + int childCount = p_desired_node->get_child_count(); + + if (p_desired_node->get_filename()==p_target_scene_path) { + return true; + } + + for (int i=0;iget_child(i); + + if(_cyclical_dependency_exists(p_target_scene_path,child)) { + return true; + } + } + + return false; +} + + static String _get_name_num_separator() { switch(EditorSettings::get_singleton()->get("scenetree_editor/duplicate_node_name_num_separator").operator int()) { case 0: return ""; -- cgit v1.2.3 From 0e8987abaf898db74b8b0278effd305673935d5e Mon Sep 17 00:00:00 2001 From: Nathan Warden Date: Tue, 20 Jan 2015 09:05:22 -0500 Subject: Fixed a bug where if a scene hadn't been saved it would find a cyclical dependency. --- tools/editor/scene_tree_dock.cpp | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) (limited to 'tools/editor/scene_tree_dock.cpp') diff --git a/tools/editor/scene_tree_dock.cpp b/tools/editor/scene_tree_dock.cpp index d8d713ee40..6f33d4b3d1 100644 --- a/tools/editor/scene_tree_dock.cpp +++ b/tools/editor/scene_tree_dock.cpp @@ -83,12 +83,16 @@ Node* SceneTreeDock::instance(const String& p_file) { return NULL; } - if (_cyclical_dependency_exists(edited_scene->get_filename(), instanced_scene)) { + // If the scene hasn't been saved yet a cyclical dependency cannot exist. + if (edited_scene->get_filename()!="") { - accept->get_ok()->set_text("Ok"); - accept->set_text(String("Cannot instance the scene '")+p_file+String("' because the current scene exists within one of its' nodes.")); - accept->popup_centered(Size2(300,90)); - return NULL; + if (_cyclical_dependency_exists(edited_scene->get_filename(), instanced_scene)) { + + accept->get_ok()->set_text("Ok"); + accept->set_text(String("Cannot instance the scene '")+p_file+String("' because the current scene exists within one of its' nodes.")); + accept->popup_centered(Size2(300,90)); + return NULL; + } } instanced_scene->generate_instance_state(); -- cgit v1.2.3