Fixed a bug where a user could add a cyclical dependency, causing a crash.
This commit is contained in:
parent
a0511ed59a
commit
92cc7b840e
2 changed files with 29 additions and 1 deletions
|
@ -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 "";
|
||||
|
|
|
@ -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();
|
||||
|
|
Loading…
Reference in a new issue