-
-
Notifications
You must be signed in to change notification settings - Fork 21.4k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Directory::change_dir Does Not Work Outside of res:// #35346
Comments
var directory = Directory.new()
directory.open("user://")
directory.change_dir("user://") |
@timothyqiu thank you for explaining this; However, this still doesn't explain why
Additionally, pathes starting with |
So there is definitely some weirdness going on here, as my observations found out:
if (base != String() && !try_dir.begins_with(base)) {
ERR_FAIL_COND_V(getcwd(real_current_dir_name, 2048) == NULL, ERR_BUG);
String new_dir;
new_dir.parse_utf8(real_current_dir_name);
if (!new_dir.begins_with(base)) {
try_dir = current_dir; //revert
}
}
// the directory exists, so set current_dir to try_dir
current_dir = try_dir;
ERR_FAIL_COND_V(chdir(prev_dir.utf8().get_data()) != 0, ERR_BUG);
return OK; Now at this point, we have already changed the directory. But here, After exiting the
bool worked = (SetCurrentDirectoryW(p_dir.c_str()) != 0);
String base = _get_root_path();
if (base != "") {
GetCurrentDirectoryW(2048, real_current_dir_name);
String new_dir;
new_dir = String(real_current_dir_name).replace("\\", "/");
if (!new_dir.begins_with(base)) {
worked = false;
}
}
if (worked) {
GetCurrentDirectoryW(2048, real_current_dir_name);
current_dir = real_current_dir_name; // TODO, utf8 parser
current_dir = current_dir.replace("\\", "/");
} //else {
SetCurrentDirectoryW(prev_dir.c_str());
//}
return worked ? OK : ERR_INVALID_PARAMETER;
} Note how it's pretty much the same thing as the Unix code, with the sole exception that we use a variable named I am not sure exactly what conditions should and shouldn't be tested here, but with further help I can go deeper down the rabbit-hole. |
Seems still valid in 3.2.4 beta4 |
And in 3.5.2, at least on macOS. Two, very similar error messages are shown when my game is accessing or deleting a save file in
Thankfully, the file gets deleted, but these messages are still unnerving. |
In Godot 4 with the new DirAccess class you have to open a directory when creating an instance. Both |
Godot version:
vGodot 3.1.2.stable.official
OS/device including version:
Windows 10
Issue description:
The method
Directory::change_dir
is not able to move to directories outsideres://
directory. This is despite the documentation show thatDirectory::change_dir
is capable of preforming such an action.Steps to reproduce:
res://
usingDirectory::change_dir
.Minimal reproduction project:
ChangeDirBug.zip
The text was updated successfully, but these errors were encountered: