summaryrefslogtreecommitdiff
path: root/tools
diff options
context:
space:
mode:
authorNathan Warden <nathanwardenlee@icloud.com>2015-01-19 15:47:50 -0500
committerNathan Warden <nathanwardenlee@icloud.com>2015-01-19 15:47:50 -0500
commit92cc7b840eff99e90b64caad6883aefbe4c3dd1e (patch)
treeb5ae556d8fb9357432c593cb46758d1e1592bdb6 /tools
parenta0511ed59a0e03232bf3abb49b3c916591453aef (diff)
Fixed a bug where a user could add a cyclical dependency, causing a crash.
Diffstat (limited to 'tools')
-rw-r--r--tools/editor/scene_tree_dock.cpp29
-rw-r--r--tools/editor/scene_tree_dock.h1
2 files changed, 29 insertions, 1 deletions
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;i<childCount;i++) {
+ Node* child=p_desired_node->get_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 "";
diff --git a/tools/editor/scene_tree_dock.h b/tools/editor/scene_tree_dock.h
index ac5391f3b9..92ebfc5bee 100644
--- a/tools/editor/scene_tree_dock.h
+++ b/tools/editor/scene_tree_dock.h
@@ -102,6 +102,7 @@ class SceneTreeDock : public VBoxContainer {
void _load_request(const String& p_path);
void _script_open_request(const Ref<Script>& p_script);
+ bool _cyclical_dependency_exists(const String& p_target_scene_path, Node* p_desired_node);
void _node_selected();
void _node_renamed();