From da2b5da0c54e9e940221e602f58ecb08a8f4efec Mon Sep 17 00:00:00 2001 From: Marios Staikopoulos Date: Tue, 5 Apr 2022 10:09:52 -0700 Subject: [PATCH] Fix Project Manager hard crashes due to invalid access to Editor Nodes --- editor/editor_dir_dialog.cpp | 11 +++++++---- editor/editor_file_dialog.cpp | 8 +++++--- editor/filesystem_dock.cpp | 14 +++++++------- 3 files changed, 19 insertions(+), 14 deletions(-) diff --git a/editor/editor_dir_dialog.cpp b/editor/editor_dir_dialog.cpp index 866f28c03be..9fabde93ef7 100644 --- a/editor/editor_dir_dialog.cpp +++ b/editor/editor_dir_dialog.cpp @@ -156,15 +156,18 @@ void EditorDirDialog::_make_dir_confirm() { String dir = ti->get_metadata(0); - if (EditorFileSystem::get_singleton()->get_filesystem_path(dir + makedirname->get_text())) { + DirAccessRef d = DirAccess::open(dir); + ERR_FAIL_COND_MSG(!d, "Cannot open directory '" + dir + "'."); + + const String stripped_dirname = makedirname->get_text().strip_edges(); + + if (d->dir_exists(stripped_dirname)) { mkdirerr->set_text(TTR("Could not create folder. File with that name already exists.")); mkdirerr->popup_centered(); return; } - DirAccessRef d = DirAccess::open(dir); - ERR_FAIL_COND_MSG(!d, "Cannot open directory '" + dir + "'."); - Error err = d->make_dir(makedirname->get_text()); + Error err = d->make_dir(stripped_dirname); if (err != OK) { mkdirerr->popup_centered(Size2(250, 80) * EDSCALE); } else { diff --git a/editor/editor_file_dialog.cpp b/editor/editor_file_dialog.cpp index 179894915bb..d5105b5ac8d 100644 --- a/editor/editor_file_dialog.cpp +++ b/editor/editor_file_dialog.cpp @@ -1099,16 +1099,18 @@ EditorFileDialog::Access EditorFileDialog::get_access() const { } void EditorFileDialog::_make_dir_confirm() { - if (EditorFileSystem::get_singleton()->get_filesystem_path(makedirname->get_text().strip_edges())) { + const String stripped_dirname = makedirname->get_text().strip_edges(); + + if (dir_access->dir_exists(stripped_dirname)) { error_dialog->set_text(TTR("Could not create folder. File with that name already exists.")); error_dialog->popup_centered(Size2(250, 50) * EDSCALE); makedirname->set_text(""); // Reset label. return; } - Error err = dir_access->make_dir(makedirname->get_text().strip_edges()); + Error err = dir_access->make_dir(stripped_dirname); if (err == OK) { - dir_access->change_dir(makedirname->get_text().strip_edges()); + dir_access->change_dir(stripped_dirname); invalidate(); update_filters(); update_dir(); diff --git a/editor/filesystem_dock.cpp b/editor/filesystem_dock.cpp index ee7ed77957b..f6d00470d17 100644 --- a/editor/filesystem_dock.cpp +++ b/editor/filesystem_dock.cpp @@ -1427,17 +1427,17 @@ void FileSystemDock::_make_dir_confirm() { directory = directory.get_base_dir(); } - if (EditorFileSystem::get_singleton()->get_filesystem_path(directory + dir_name)) { + print_verbose("Making folder " + dir_name + " in " + directory); + DirAccessRef da = DirAccess::create(DirAccess::ACCESS_RESOURCES); + Error err = da->change_dir(directory); + ERR_FAIL_COND_MSG(err != OK, "Cannot open directory '" + directory + "'."); + + if (da->dir_exists(directory)) { EditorNode::get_singleton()->show_warning(TTR("Could not create folder. File with that name already exists.")); return; } - print_verbose("Making folder " + dir_name + " in " + directory); - DirAccessRef da = DirAccess::create(DirAccess::ACCESS_RESOURCES); - Error err = da->change_dir(directory); - if (err == OK) { - err = da->make_dir(dir_name); - } + err = da->make_dir(dir_name); if (err == OK) { print_verbose("FileSystem: calling rescan.");