Skip to content
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

Safe save fails way too often #40366

Open
CenTdemeern1 opened this issue Jul 14, 2020 · 34 comments
Open

Safe save fails way too often #40366

CenTdemeern1 opened this issue Jul 14, 2020 · 34 comments

Comments

@CenTdemeern1
Copy link

Couldn't find any potential dupes.

Godot version:
3.2.1.stable
3.2.2.stable
These two versions of Godot are the only ones I've ever used, and it happens on both of them.

OS/device including version:
Microsoft Windows NT Version 10.0.18363.900 running on an Intel Core i3 and integrated graphics,
This is not a visual problem.

Issue description:
I keep experiencing a certain issue, and I'm getting sick of it.
It happens sometimes when I do one or more of these things:

  • Run the project
  • Export the project
  • Save a change while it's running
  • Save a change while it's not running (although it happens less often when not running!)
  • Adding a file to the project
    The issue I'm experiencing is this:
    ERROR: Safe save failed. This may be a permissions problem, but also may happen because you are running a paranoid antivirus. If this is the case, please switch to Windows Defender or disable the 'safe save' option in editor settings. This makes it work, but increases the risk of file corruption in a crash.
    Firstly, no, Switching to Windows Defender doesn't solve the issue.
    Secondly, my antivirus isn't picking up Godot.
    And lastly, disabling safe save doesn't help.
    What I think the issue is is that it's trying to write to a file that's in use.

Steps to reproduce:
I think you have the best chance at getting this when saving a change to scene X while it's using scene X.

Minimal reproduction project:
N/A

@CenTdemeern1 CenTdemeern1 changed the title Save safe fails way too often Safe save fails way too often Jul 14, 2020
@Rubonnek
Copy link
Member

@CenTdemeern1 Any chance you could give us a minimal project to reproduce this problem? It will help us fix the problem faster.

@CenTdemeern1
Copy link
Author

Nope! This isn't project dependant or anything.
It just happens, across multiple projects.
Not across computers though!
Or at least, when project X fails to safe save on computer A, it doesn't do it per se on computer B.

@CenTdemeern1
Copy link
Author

That's why I put N/A (Not applicable) in the reproduction project section.

@Calinou
Copy link
Member

Calinou commented Jul 15, 2020

@CenTdemeern1 If you can only reproduce this on a single machine, then it is most likely related to the particular software configuration of the machine in question. Try disabling any and all antivirus programs and check again (Windows Defender can be disabled temporarily or permanently).

@CenTdemeern1
Copy link
Author

I can definitely reproduce this on another machine!

@CenTdemeern1
Copy link
Author

It's just that it doesn't depend on anything related to any specific project.
It's a general issue that happens everywhere on anything at any time randomly.

@Rubonnek
Copy link
Member

Now that I think about it I've been experiencing some quite random crashes on Linux lately that seem to be related to this. I thought they were related to the LSP server, but this seems more reasonable.

If I were to guess it's a buffer overflow or stack smash we are not catching.

On Linux we don't build the engine with -D_FORTIFY_SOURCE=2 for performance reasons, but I'll do that on my end and see if the canaries catch an error.

@CenTdemeern1
Copy link
Author

Oh! I just remembered.
This is not the only error or whatever that occurs in the same way as this.
Sometimes, when running from the editor, it randomly fails to connect to the process for debugging.

@Rubonnek
Copy link
Member

Rubonnek commented Jul 16, 2020

Hmm... looks like this issue is far more specific to Windows. I've been running Godot with the GCC canaries and I have not been able to reproduce a crash after all.

@ChildishGiant
Copy link

I'm getting this without any antivirus other than windows security. I've tried turning off windows security too and still have this issue. If I restart godot I'm able to save the file but after a bit it will protest. I've not had this issue on my linux machine.

ERROR: Safe save failed. This may be a permissions problem, but also may happen because you are running a paranoid antivirus. If this is the case, please switch to Windows Defender or disable the 'safe save' option in editor settings. This makes it work, but increases the risk of file corruption in a crash.
   At: drivers/windows/file_access_windows.cpp:183

@CenTdemeern1
Copy link
Author

This stuff seems to be happening because the file is in use
That's what I think, at least

@MoZZez
Copy link

MoZZez commented Jan 9, 2022

Here is a bit more on the issue:
I am learning Godot and so not being very familiar with GDScript sometimes make mistakes.
For example instead of writing this:
velocity = move_and_slide(velocity, Vector2.UP) - The right way to write the statement.
I wrote this:
velocity = move_and_slide(velocity, up_direction=Vector2.UP) - like python kwarg.
After that I experienced a warning and later an error - unexpected assignment.
And here is the thing, after I added this wrong piece of code and tried to compile-run(F5) my project and it ran with black window of a game(because it was no more working), any attempts to save project have raised the error mentioned:

ERROR: Safe save failed. This may be a permissions problem, but also may happen because you are running a paranoid antivirus. If this is the case, please switch to Windows Defender or disable the 'safe save' option in editor settings. This makes it work, but increases the risk of file corruption in a crash.

Not sure, is it much of a help, but that's another way to trigger it, and I think its out of place for it to be raised in this case.
UPDATE:
Also, if I fix code error and run project again, I can normally save it. Seems like for bugged project engine is not stopping to use it correctly if ran like that, but it resets somehow when you run it again with no code errors.

@felipefacundes
Copy link

This is a bug for sure. I'm going through the same problem. Every time this happens, I have to create a new project and port everything there, which slows down production a lot. It gets in the way too much! And also if you try to "save as" it doesn't allow overwriting. I'm using the latest stable version of Godot 3.4.2. Please check this as it is a bug that was present in previous versions. Look at this post is from 2020 and it hasn't been fixed yet.

In my case my problem is not with the GDScript itself, but with saving an existing scene that I had to change, when creating a node or when I am going to change the scene

I reported this error as well
https://godotengine.org/qa/80242/scene-not-saving

@Calinou Calinou added this to the 4.0 milestone Feb 12, 2022
@Calinou
Copy link
Member

Calinou commented Feb 12, 2022

@mhilbrunner did some work to try to address this in #51430, but it's a neverending battle to find and fix all the Windows file access issues.

@felipefacundes
Copy link

So I use Linux (Arch) and this problem occurs when saving or overwriting the file or a simple scene, the strange thing is that even when I go to save as a new file or a new scene, the changes are not made. If I don't make a backup of the project directory ( cp dir_project dir_project.bak) I lose everything. Sometimes this bug occurs when I am simply going to create a new node. Or just change the scenario a bit. When the bug occurs I lose everything and have to resort to manual directory backup. From what I've seen it's a bug that was reported in Godot 2.0.2 and that still persists in 3.4.2.

#4545

@felipefacundes
Copy link

I believe it must be because some unwanted.lock file is created preventing simple saving or to another file...

@Calinou
Copy link
Member

Calinou commented Feb 13, 2022

I believe it must be because some unwanted.lock file is created preventing simple saving or to another file...

Godot doesn't create lock files of any kind, but it performs "safe" file saving which you can disable in the Editor Settings. If you disable it, you will no longer have the guarantee that files will be fully written by Godot (in the event of a crash or power failure).

@felipefacundes
Copy link

Yes, I am aware of this procedure and have already tested it. Even with safe save enabled or disabled, I have problems with some node changes, minimal changes to the scenario. As I said when the bug happens I have to resort to the backup folder that I have to create manually every time. It is a bug that I see occurring since the previous versions. I'm waiting for the bug fixes with each update but the bug remains, it's the first time I report this, because I'm tired of having to keep restoring the old directory and losing all my progress. As I said, I find it strange not to allow or save as a new scene, when the bug persists, it simply doesn't save anything, it doesn't overwrite, in short, it becomes unusable. This is very complicated!

@KoBeWi KoBeWi removed this from the 4.0 milestone Apr 30, 2022
@barrrettt
Copy link

restart windows solve

@sszigeti
Copy link

This happens to me occiasionally on Windows 11 with v4.1.2.stable.mono.official [399c9dc]. Disabling "safe save" (Editor Settings -> FileSystem -> On Save -> Safe Save on Backup then Rename) doesn't prevent it happening. I'm also not using any antivirus (beyond what's present in Windows 11 by default).

Rarely I get the following errors opening in a "Load Errors" prompt window which doesn't let me copy them, but it lists 4 times the same error (at least they all begin with a red dot, usually signifying errors):

Unable to write to file 'C:/Users/MyName/AppData/Local/Godot/resthumb-someLongHexadecimalString.txt', file in use, locked or lacking permissions.

After closing this window I can continue editing and running my project.

@NangiDev
Copy link

NangiDev commented Oct 27, 2023

I've had the same issue on Windows 11.
I could not get any suggestion to work.

What worked for me was

  • rename %appdata%/Godot
  • start Godot
  • close Godot
  • delete new %appdata%/Godot
  • rename %appdata%/Godot back to original
  • start Godot

Not sure why though

Edit: It came back...
Instead of renaming %appdata%/Godot I just deleted it.

Edit2: I saw that there was quite a big size difference (1GB) of the old and new %appdata%/Godot
Also the old one was from April this year. Could it be that because I did a engine update recently my new engine didn't have permissions to some folders?

Edit3: Does this image maybe help someone tracking down the issue? its WinMerge compare of the old and new %appdata%/Godot

image

@ilia-abbasi
Copy link

ilia-abbasi commented Nov 2, 2023

Godot v4.1.2.stable - Windows 10.0.19045 - Vulkan (Compatibility) - GeForce 9400 GT () - Intel(R) Pentium(R) CPU G4400 @ 3.30GHz (2 Threads)

I have the same problem in 4.1.2
Actually I encountered this bug only in the 4.1.2 version. I have spent much more time on 4.1.1 but the bug never appeared there.
Sometimes the bug doesnt let me run the project, and sometimes it does but it appears for a very short amount of time before running the project, and then it disappears like it never happened.
The .tscn file that the bug refers to is not the scene that I have recently made changes to. Each time it has a problem with a random file in my project.
Turning the anti-virus off doesnt help.

@SilentPrayeCG
Copy link

SilentPrayeCG commented Nov 5, 2023

I think I have same issue. I started with Godot 4.1.1, I think, and when I updated to 4.1.2
it's started to show "loads errors"

  • unable to write to file - and path to random restthumb~.txt - file in use, locked or lacking permission.

And in output console it says: Safe save failed. Bla-bla-bla.
I have only windows defender, and I do not accept solution to disable it. It do not interfere with anything else, and I added that "app data" folder to exclusions.
Tho, I'm only assume this is connected.

@NangiDev
Copy link

If my theory is correct it has nothing to do with antivirus, but ownership of the files/directories inside %appdata%/Godot.

This is how I think it happend:

  1. Install Godot 4.0. %appdata%/Godot is created and process owner is Godot 4.0
  2. Install Godot 4.1. It's getting the crashes because the %appdata%/Godot is owned by 4.0.

In a lot of other software there is the update-button that solves this issue, but in game engines we want to be able to have several versions. Thus Epic and Unity has their Launcher and Hub that is suppose to solve these kind of problems.

Because Godot don't have a official engine version manager maybe it would be smart to maybe separate the different appdata directories between versions?

Ex:
%appdata%/Godot/v4.0
%appdata%/Godot/v4.1
%appdata%/Godot/v4.2

@SilentPrayeCG
Copy link

If my theory is correct it has nothing to do with antivirus, but ownership of the files/directories inside %appdata%/Godot.

This is how I think it happend:

1. Install Godot 4.0. %appdata%/Godot is created and process owner is Godot 4.0

2. Install Godot 4.1. It's getting the crashes because the %appdata%/Godot is owned by 4.0.

In a lot of other software there is the update-button that solves this issue, but in game engines we want to be able to have several versions. Thus Epic and Unity has their Launcher and Hub that is suppose to solve these kind of problems.

Because Godot don't have a official engine version manager maybe it would be smart to maybe separate the different appdata directories between versions?

Ex: %appdata%/Godot/v4.0 %appdata%/Godot/v4.1 %appdata%/Godot/v4.2

You can easily check ownership of the folder. And it's regular permissions.
Also program can't be an owner, only user.

I'm also pretty sure it have nothing to do with antivirus. It can't write some text file, with same name (except extension) as png picture thumbnail that contain screenshot of viewport. At least in my case.

@Calinou
Copy link
Member

Calinou commented Nov 14, 2023

Which process creates the folder doesn't matter, as long as there is only one process at a time accessing a file for writing.

@SilentPrayeCG
Copy link

Which process creates the folder doesn't matter, as long as there is only one process at a time accessing a file for writing.

And nothing but Godot itself can lock same file every time this happen. No way it's something else. And it can't be Windows Defender. I put Godot Temp Folder in to exclusions.
Also programs like Lock Hunter, doesn't show any programs locking anything in that folder. I assume it's something that happens on some precise moment. Like, maybe, Godot trying load and save this file at same time. Or trying save it twice from different threads or something like that. Tho it's only my assumption.

@sdehan
Copy link

sdehan commented Nov 14, 2023

I noticed that when my editor setting export/android/android_sdk_path="" is assigned a path, launching the project results in the error 'Safe Save Failed.' However, when the path is empty, the error disappears.

@DexeloperGames
Copy link

I noticed that when my editor setting export/android/android_sdk_path="" is assigned a path, launching the project results in the error 'Safe Save Failed.' However, when the path is empty, the error disappears.

No wonder this error started happening at the same time i started trying to export for android, clearing the SDK path fixed it!

@Calinou
Copy link
Member

Calinou commented Nov 22, 2023

For those who have an Android SDK path set in the Editor Settings, does this only occur in projects that have an Android export preset configured? Does it still occur if you disable Runnable on all Android export presets and reload the editor?

Edit: It seems adb always starts even if it's not needed: #85246

@Infini-Creation
Copy link

I get a way to 100% reproduce the issue which may, or may not, match other users case, they all need to check to be sure it's not something similar or related to my finding.

But first, let's start by a little story:
I have used windows 7 for a long time, almost ten years, and starting using Godot playing with some projects.
A few months after, I decide to move to windows 10, finally, so bought new drives, install a fresh OS, drivers & tools, Godot, ... I also copy many projects started on the previous OS (which then have been owned by a user of the old OS identified by some internal ID)
It's only when I edit one of this old project on the new OS I've encountered the issue, triggered by a "ghost" owner which doesn't match current user ID.
Windows explorer usually deal with this issue typically as a windows tool, by asking privilege escalation using administrator rights on problematic files & directories.

So here is how to trigger the issue with, I'm quite confident, 99.99 % certainty, it need although two different windows installations more or less unrelated to each other, using NTFS filesystems:

-on computer A:
-create a project
-add some scenes, some scripts
-save
-put files as-is on a thumb drive, hard drive, whatever

-on computer B:
-copy project from computer A (better to take hard-drive of A and use it on B as USB external drive)
-open it with Godot without changing anything using an unprivileged account (run as a regular user)

It's just happened to me yesterday when I tried an old project (last edited with some 4.0 version of Godot on my previous windows install), start was slow, lot's of error messages, veerrryyyyyy sluggish start of main scene, like about 2 mins.

godot-4 2-oldproject4 0-issue

I have edited ownership to replace old nonexistent account to the user of the currently used system (here is a sample of the old account ID):
godot-4 2-oldproject4 0-issue-unknow-owner

Now Godot open the project in the time needed to load assets and process files only (quite short, a few secs), no error, no pop-up window
running the main scene is quite instantaneous.

On another project, I even got an empty "load errors" window:
godot-4 2-oldproject4 0-issue-emptyloaderror

Note: to edit and fix ownership, is a bit fastidious and weird as quite usual with windows stuff, I didn't take notes of the full process, you have to replace owner, remove inheritance of parent rights or something like that to be able to remove old owner of directories.

I guess on Unix based systems, unless users have been created in the same order, both Godot and users should get filesystem errors, most likely for writing, as reading should be ok.

I suggest to improve windows errors management code to first add ownership hint BEFORE antivirus one as it is misleading, and avoiding to use a retry/delay loop for errors which CANNOT fixed themselves with time as opposite to network errors. There is no point to retry n times before finally giving up, making the editor quite frozen in the process, delay looks also very short to be helpful at all.

@HarperCT
Copy link

Godot v 4.2
Maybe very far left field but I also get this while trying to build my Godot project using GitHub Actions automation tool (I don't have permission to how GitHub do this) . Running locally on my machine (even with safe save on) works totally fine tho.
This may support the "Anti virus bad" theory.

@goranovs
Copy link

Godot v 4.2.1
I got the same error and the editor created bunch of .tmp files. and shows dialog with:

Unable to write to file 'C:/Users/MyName/AppData/Local/Godot/resthumb-someLongHexadecimalString.txt', file in use, locked or lacking permissions.

Every attempt to save with "CTR+S" shows dialog with the above error and create new .tmp file.

I've tried to find the file in AppData\Local\Godot and there was none. Then I've tried to rename the Godot folder and Windows 11 told me the folder is in use by another program. Godot Editor was closed. Then I've noticed in the working processes a java program.

image
it keeps eating memory. I've killed the process and the Godot folder was free and I was able to rename it. Godot Editor now seems to be able to save with no issues.

For me the java program starts when I deploy to my android phone via Remote Debug. I often unplug my phone to test around the house. There is no stop button in the editor for remote debug and the process seems to get stuck. This action also breaks the remote debug session and if I deploy again there is no debug session at all. No output and etc.

I assume at some point the process gets so stuck or second process is started and that locks the Godot folder. For now I can't reproduce the locked folder again, but killing the process fixed the save problem for me without any restarts of the OS.

@Shadowblitz16
Copy link

Shadowblitz16 commented Sep 3, 2024

I am getting this on kubuntu 24.04 with godot 4.3-stable
image

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests