godotengine / godot

Godot Engine – Multi-platform 2D and 3D game engine
https://godotengine.org
MIT License
88.75k stars 20.12k forks source link

Saving on Windows succeeds but shows error message dialog (due to file locking limitations) #6393

Closed amedlock closed 2 years ago

amedlock commented 8 years ago

Operating system or device - Godot version: Windows 7 64 bit professional

Issue description (what happened, and what was expected): Editing and saving a script repeatedly seems to cause the following error: Unable to write to file 'e:/proj/myproject/script/test.tscn' , file in use, locked or lacking permissions.

This is in the log: ERROR: FileAccessWindows::close: Condition ' rename_error ' is true. At: drivers\windows\file_access_windows.cpp:139 ERROR: FileAccessWindows::close: Condition ' rename_error ' is true. At: drivers\windows\file_access_windows.cpp:139

Steps to reproduce: Just changing and editing a script file seems to cause it.

Link to minimal example project (optional but very welcome):

amedlock commented 8 years ago

Looking further, this only happens when stopped with error in debugger.

reduz commented 8 years ago

do you have the script files opened by something else, like an external editor?

vnen commented 8 years ago

I've seen this, usually when the scene is running, but I can't reproduce reliably.

IBwWG commented 7 years ago

For me the scripts are not open in a separate editor, and I was getting this sporadically but now it's just about every save. Godot 2.1.1 on win7x64.

IBwWG commented 7 years ago

Also in my case often (but not always) the saving isn't succeeding. Obvious changes made etc. are not present in what's run.

Possible lead, TortoiseGit caching...could this have been the case for you @amedlock or @vnen ?

IBwWG commented 7 years ago

Yeah this bug really slowed down my save/reload cycle....

Sslaxx commented 7 years ago

Perhaps this needs to be re-opened.

IBwWG commented 7 years ago

I would say so...not to be a snob about it but I stuck it through for LD 37, but would not want to use Godot again until that was fixed. Not a show-stopper but a real grind-it-to-a-near-halt-er with no obvious workaround. It seemed like every 10th save sometimes, or sometimes every 2nd save, would just mysteriously work.

You're not supposed to run as admin or anything, are you?

amedlock commented 7 years ago

I had no TortoiseGit running, or Dropbox/Google drive. Seemed to just be windows holding the file handle sometimes.

bojidar-bg commented 7 years ago

Isn't it that the currently running game is holding the file handle, or am I wrong?

IBwWG commented 7 years ago

Sorry @bojidar-bg but it couldn't be that way even if I wanted to--my game captures the mouse, so I almost always exited it to return to the GUI, unless I was inspecting something in-game. I just tried it now to be sure, and the game definitely isn't running when I get the error.

bojidar-bg commented 7 years ago

Then.. maybe the editor has the handle? :smile:

IBwWG commented 7 years ago

Then shouldn't it...you know...use it to save the file?

bojidar-bg commented 7 years ago

@IBwWG All bugs are about a "shouldn't it", and this one is deep within drivers/windows probably.

IBwWG commented 7 years ago

But, if Godot is still holding an open file handle, shouldn't it tell Windows to close it when it's done with it? (I have no idea if the problem is Windows or Godot, but I don't have this problem with other programs. What makes you think it's Windows rather than Godot?)

One other thing I noticed: it's complaining about main.scn, which I have to have open in order to save (otherwise it tells me I need to have a root file open) and run the project. I have it open, but I am not touching it at all between saves: I'm purely editing .gd files. Is that behaviour itself maybe part of the problem?

Zylann commented 7 years ago

I get such errors frequently on Windows 10, even when I don't actually save.

An occurence of it in 3.0 master (here when running the game): image

Toshiwoz commented 7 years ago

I have this problem to, aslo with the 2.1.3 RC1, can't tell but, can it be because I also tried with the 3.0 version compiled by the fixnum guys(http://fixnum.org/godot/)?

I've also noticed that this issue prevents godot from generating scenes preview (or thumb, or preview, dunno hot to call it).

I didn't had this problem since the beginning.

Toshiwoz commented 7 years ago

Same thing withRC2 and now with the fresh new stable release. Can it be because the project was created using 2 different versions?

Toshiwoz commented 7 years ago

And by the way it is also happening when editing scenes or saving editor config. image

The, how do yu call it.. debug window? Tells me the error is this:

ERROR: FileAccessWindows::close: Condition ' rename_error ' is true.
   At: drivers\windows\file_access_windows.cpp:130
ERROR: SpatialIndexer::_update_camera: Condition ' !E ' is true.
   At: scene\resources\world.cpp:125

And here is the code it is referring to:

if (!PathFileExistsW(save_path.c_str())) {
#endif
            //creating new file
            rename_error = _wrename((save_path + ".tmp").c_str(), save_path.c_str()) != 0;
        } else {
            //atomic replace for existing file
            rename_error = !ReplaceFileW(save_path.c_str(), (save_path + ".tmp").c_str(), NULL, 2 | 4, NULL, NULL);
        }

Can it be that the .tmp files instead of being renamed are copied and then when it tries to create again the .tmp file it fails? (sorry I am going to sleep, don't have enough time to look into that deeper)

reduz commented 7 years ago

Godot does not keep handles open to existing files, it is likely thar the text editor you are using does, so Godot is unable to save over them. Does it happen with other text editors?

On Apr 15, 2017 5:35 AM, "Toshio Araki" notifications@github.com wrote:

And by the way it is also happening when editing scenes or saving editor config. [image: image] https://cloud.githubusercontent.com/assets/21297356/25060359/da190f24-2160-11e7-8362-1b53e5f58c0a.png

The, how do yu call it.. debug window? Tells me the error is this:

ERROR: FileAccessWindows::close: Condition ' rename_error ' is true. At: drivers\windows\file_access_windows.cpp:130 ERROR: SpatialIndexer::_update_camera: Condition ' !E ' is true. At: scene\resources\world.cpp:125

And here https://github.com/godotengine/godot/blob/master/drivers/windows/file_access_windows.cpp is the code it is referring to:

if (!PathFileExistsW(save_path.c_str())) {

endif

      //creating new file
      rename_error = _wrename((save_path + ".tmp").c_str(), save_path.c_str()) != 0;
  } else {
      //atomic replace for existing file
      rename_error = !ReplaceFileW(save_path.c_str(), (save_path + ".tmp").c_str(), NULL, 2 | 4, NULL, NULL);
  }

Can it be that the .tmp files instead of being renamed are copied and then when it tries to create again the .tmp file it fails? (sorry I am going to sleep, don't have enough time to look into that deeper)

— You are receiving this because you commented. Reply to this email directly, view it on GitHub https://github.com/godotengine/godot/issues/6393#issuecomment-294269381, or mute the thread https://github.com/notifications/unsubscribe-auth/AF-Z21l6URkaTW70lxXFkkRwtcKQyYS6ks5rwDrmgaJpZM4J0jlH .

reduz commented 7 years ago

This only happens if a handle to the file is opened while godot tries to save.. I think there are ways in windows to ask who is owning the file lock

On Apr 15, 2017 6:20 AM, "Juan Linietsky" reduzio@gmail.com wrote:

Godot does not keep handles open to existing files, it is likely thar the text editor you are using does, so Godot is unable to save over them. Does it happen with other text editors?

On Apr 15, 2017 5:35 AM, "Toshio Araki" notifications@github.com wrote:

And by the way it is also happening when editing scenes or saving editor config. [image: image] https://cloud.githubusercontent.com/assets/21297356/25060359/da190f24-2160-11e7-8362-1b53e5f58c0a.png

The, how do yu call it.. debug window? Tells me the error is this:

ERROR: FileAccessWindows::close: Condition ' rename_error ' is true. At: drivers\windows\file_access_windows.cpp:130 ERROR: SpatialIndexer::_update_camera: Condition ' !E ' is true. At: scene\resources\world.cpp:125

And here https://github.com/godotengine/godot/blob/master/drivers/windows/file_access_windows.cpp is the code it is referring to:

if (!PathFileExistsW(save_path.c_str())) {

endif

     //creating new file
     rename_error = _wrename((save_path + ".tmp").c_str(), save_path.c_str()) != 0;
 } else {
     //atomic replace for existing file
     rename_error = !ReplaceFileW(save_path.c_str(), (save_path + ".tmp").c_str(), NULL, 2 | 4, NULL, NULL);
 }

Can it be that the .tmp files instead of being renamed are copied and then when it tries to create again the .tmp file it fails? (sorry I am going to sleep, don't have enough time to look into that deeper)

— You are receiving this because you commented. Reply to this email directly, view it on GitHub https://github.com/godotengine/godot/issues/6393#issuecomment-294269381, or mute the thread https://github.com/notifications/unsubscribe-auth/AF-Z21l6URkaTW70lxXFkkRwtcKQyYS6ks5rwDrmgaJpZM4J0jlH .

Toshiwoz commented 7 years ago

No entiendo, I'm using godot only, no text editor. The function ReplaceFileW does a replace. So as far as I understand it takes, for example, the editor_settings.tres doing a copy of it as a .tmp file, and up to that it works fine, then it tries to replace the content of the original file with the .tmp one, and here I think is where it fails. To me it's probable that it's godot itself not releasing handle of the files when it should. Or that function has some wrong parameters.

reduz commented 7 years ago

Maybe some recent commit or pr relate to windows backend for for file access broke this?

On Sat, Apr 15, 2017 at 4:49 PM Toshio Araki notifications@github.com wrote:

No entiendo, I'm using godot only, no text editor. The function ReplaceFileW does a replace. So as far as I understand it takes, for example, the editor_settings.tres doing a copy of it as a .tmp file, and up to that it works fine, then it tries to replace the content of the original file with the .tmp one, and here I think is where it fails. To me it's probable that it's godot itself not releasing handle of the files when it should. Or that function has some wrong parameters.

— You are receiving this because you commented.

Reply to this email directly, view it on GitHub https://github.com/godotengine/godot/issues/6393#issuecomment-294297888, or mute the thread https://github.com/notifications/unsubscribe-auth/AF-Z27SyMadtziGM_bayn-O-Tm5sN-1xks5rwNj-gaJpZM4J0jlH .

reduz commented 7 years ago

I don't see anything relevant, anyone willing to test from which commit it breaks?

On Sat, Apr 15, 2017 at 4:56 PM Juan Linietsky reduzio@gmail.com wrote:

Maybe some recent commit or pr relate to windows backend for for file access broke this?

On Sat, Apr 15, 2017 at 4:49 PM Toshio Araki notifications@github.com wrote:

No entiendo, I'm using godot only, no text editor. The function ReplaceFileW does a replace. So as far as I understand it takes, for example, the editor_settings.tres doing a copy of it as a .tmp file, and up to that it works fine, then it tries to replace the content of the original file with the .tmp one, and here I think is where it fails. To me it's probable that it's godot itself not releasing handle of the files when it should. Or that function has some wrong parameters.

— You are receiving this because you commented.

Reply to this email directly, view it on GitHub https://github.com/godotengine/godot/issues/6393#issuecomment-294297888, or mute the thread https://github.com/notifications/unsubscribe-auth/AF-Z27SyMadtziGM_bayn-O-Tm5sN-1xks5rwNj-gaJpZM4J0jlH .

Toshiwoz commented 7 years ago

I dunno if it has to deal with the problem but, when I start Godot I see this... image Why it does prints 3 times the exe file path?

eon-s commented 7 years ago

@Toshiwoz is just showing a path text 3 times. Can you try running it in self contained mode? In 2.1.3 should work making a file called _sc_ (nothing more) in the same directory where the Godot executable is located.

Toshiwoz commented 7 years ago

OK, just did that, same thing, it just created config files into the same folder as the editor is. image

Dpnt know if it helps but: ... EXEC PATHP??: C:\Users\Leo\Documents\TRABAJO-LEO\Godot_v2.1.3-stable_win64.exe WARNING: EditorSettings::create: Config file does not exist, creating. At: editor\editor_settings.cpp:336 SCAN PROJECTS AT: C:/Users/Leo/Documents/TRABAJO-LEO/SoftwareProjects/godot-SpaceDynamics found: 1 projects. OPENING: C:/Users/Leo/Documents/TRABAJO-LEO/SoftwareProjects/godot-SpaceDynamics (C:::Users::Leo::Documents::TRABAJO-LEO::SoftwareProjects::godot-SpaceDynamics) EXEC PATHP??: C:\Users\Leo\Documents\TRABAJO-LEO\Godot_v2.1.3-stable_win64.exe running cmdline: "C:\Users\Leo\Documents\TRABAJO-LEO\Godot_v2.1.3-stable_win64.exe" "-path" "C:/Users/Leo/Documents/TRABAJO-LEO/SoftwareProjects/godot-SpaceDynamics" "-editor" ... ERROR: FileAccessWindows::close: Condition ' rename_error ' is true. At: drivers\windows\file_access_windows.cpp:130 ERROR: SpatialIndexer::_update_camera: Condition ' !E ' is true. At: scene\resources\world.cpp:125 WARNING: AudioDriverRtAudio::callback: RtAudio output underflow! At: drivers\rtaudio\audio_driver_rtaudio.cpp:57 ...

Zireael07 commented 7 years ago

Oh yeah, I'm seeing the triple EXEC PATH line too, and the RtAudio output underflow, too.

Toshiwoz commented 7 years ago

Ok removed a bit of non relevant output... anyhow, possibly the only relevant message is: ERROR: FileAccessWindows::close: Condition ' rename_error ' is true. At: drivers\windows\file_access_windows.cpp:130

...Maybe I still have on my pc the good'ol filemon.

jesperkondrup commented 7 years ago

I know this is an old issue but I have been seeing the same message "Unable to write to file... file in use, locked or lacking permission" for the last 2-3 weeks. It happens when I save a scene in Godot but not every time.

Running Godot 2.1.2 and Windows 10.

Zylann commented 7 years ago

I still get this from time to time in master too.

bitbionic commented 6 years ago

This is still an issue in the 3.0 beta1.. I get this consistently on both of my windows boxes: capture

Archoney commented 6 years ago

Hi, I have also experienced frequent load errors, like the one above when for ex. saving scene, or running scene, or even when creating a script. I have connected this problem with avast antivirus, because when avast protection was turned off then the problem was gone.

Running master branch on Windows 10

eon-s commented 6 years ago

@Archoney There is a new option (probably on RC2) that may have solved this, look #14339

jesperkondrup commented 6 years ago

Disabling my AVG antivirus fixed the issue for me. I am running 2.1.4 beta and Win10.

The messages often appears when importing a new texture atlas or saving a scene. But with Antivirus disabled I don't see it.

LiamDobbelaere commented 6 years ago

Disabling AVG does not work for me, I still have this issue in 3.0.2 x64. It also locks up now when it happens, not even able to save editor settings. I've already tried setting the folder it tries saving to to "all permissions for Everyone" and "No read-only files". Didn't work.

Moving Godot to Program Files temporarily worked once for some reason, but not again after restart. It drives me absolutely crazy, editor has become pretty much unusable at this point

akien-mga commented 6 years ago

I think this was fixed by #17869 in the master branch (3.1) and in the upcoming 3.0.3.

If you still experience this issue in 3.0.3, please comment here or open a new bug report.

Toshiwoz commented 6 years ago

I'm not experiencing this error anymore. 👍 thanks to whoever fixed it.

Edit: I'm still experiencing it, but only occasionally, on Godot 3.1 official build. Not sure which conditions are behind this, if it happens only when saving during debugging, or if it's due to use of threads.

joting commented 5 years ago

I'm still getting this error on 3.1-beta3 and 3.0.6, but only when trying to save a scene/script that has stopped with an error, like @amedlock mentioned. It's not terrible, but it is slightly annoying.

than10AM commented 5 years ago

Still having this error. Have no Idea what to do but removing Godot.

WolfGangsta commented 4 years ago

This error is still around as of 3.2.1 on Windows 10. I don't have Avast, just Windows Defender.

I tried poking around with file and folder permissions, but everything looked normal. Godot is just failing to create or change any files, be they in AppData or my Documents folder...

Calinou commented 4 years ago

@WolfGangsta Does the situation improve if you add the Godot executable to the list of executables ignored by Windows Defender? Alternatively, try adding Documents and %APPDATA% to the list of folders ignored by Windows Defender.

WolfGangsta commented 4 years ago

Unfortunately, no. The same error messages are generated on starting the Project Manager as before:

ERROR: create: Cannot create cache directory!
   At: editor/editor_settings.cpp:863
ERROR: save: Cannot save EditorSettings config, no valid path
   At: editor/editor_settings.cpp:1052

Trying to open a test project file directly from File Explorer:

ERROR: make_dir_recursive: Method failed. Returning: err
   At: core/os/dir_access.cpp:175
ERROR: Error attempting to create data dir: C:/Users/owend/AppData/Roaming/Godot/app_userdata/Test.
   At: core/os/os.cpp:469
ERROR: create: Cannot create cache directory!
   At: editor/editor_settings.cpp:863
ERROR: save: Cannot save EditorSettings config, no valid path
   At: editor/editor_settings.cpp:1052
ERROR: Cannot create file 'C:\Users\owend\AppData\Roaming/Godot/projects/filesystem_cache6'. Check user write permissions.
   At: editor/editor_file_system.cpp:328
ERROR: Cannot save editor settings to file 'C:\Users\owend\AppData\Roaming/Godot/projects/project_metadata.cfg'.
   At: editor/editor_settings.cpp:1242
ERROR: Couldn't save project.godot - C:/Users/owend/OneDrive/Documents/Godot/Test/project.godot.
   At: core/project_settings.cpp:748
ERROR: Couldn't save project.godot - C:/Users/owend/OneDrive/Documents/Godot/Test/project.godot.
   At: core/project_settings.cpp:748
ERROR: Can't save PNG at path: 'C:\Users\owend\AppData\Local\Temp/Godot/resthumb-ee8051cd8a1d26651c8235db2deadf73.png'.
   At: drivers/png/resource_saver_png.cpp:58
ERROR: Can't save PNG at path: 'C:\Users\owend\AppData\Local\Temp/Godot/resthumb-ee8051cd8a1d26651c8235db2deadf73_small.png'.
   At: drivers/png/resource_saver_png.cpp:58
ERROR: Cannot create file 'C:\Users\owend\AppData\Local\Temp/Godot/resthumb-ee8051cd8a1d26651c8235db2deadf73.txt'. Check user write permissions.
   At: editor/editor_resource_preview.cpp:205
ERROR: Can't save PNG at path: 'C:\Users\owend\AppData\Local\Temp/Godot/resthumb-f4592acc6461da18772508b7db1bfb78.png'.
   At: drivers/png/resource_saver_png.cpp:58
ERROR: Cannot create file 'C:\Users\owend\AppData\Local\Temp/Godot/resthumb-f4592acc6461da18772508b7db1bfb78.txt'. Check user write permissions.
   At: editor/editor_resource_preview.cpp:205
eon-s commented 4 years ago

@WolfGangsta try using the editor from a non-common folder (not on user directories or program files) and use the self-contained mode, that way you will see the editor data folder created next to the editor executable, if you do not have problems running the editor that way, then windows is blocking the editor for some reason (untrusted downloaded executable or something like that).

WolfGangsta commented 4 years ago

Aha! I created a new "Godot Editor" folder in the root C: directory and stuck the executable there. Editing, saving, etc. works now, and I didn't have to use self-contained mode. The editor's data remains happily in my user's AppData folder. Thanks for the help!

It does seem a little hacky, though--as a Windows user, I'd expect to find the program in Program Files or some other common directory. I never saw any general recommendation on where to put the .exe, which is why I experimented with putting it in different places to start with. Maybe the issue is that we need more documentation on the subject of Windows "installation"?

Calinou commented 4 years ago

It does seem a little hacky, though--as a Windows user, I'd expect to find the program in Program Files or some other common directory.

If you want to install a program user-wide in a standard location, create a folder in %LOCALAPPDATA%, place the executable there and create a start menu shortcut pointing to the executable. Program Files is read-only for unprivileged users and is intended to be used for system-wide installations only.

Maybe the issue is that we need more documentation on the subject of Windows "installation"?

See #8057. Note that the Godot community is quite attached to the concept of not having to install Godot, so installers will be completely optional if they're ever released.

PS: You may be interested in Scoop :slightly_smiling_face:

# After installing Scoop, run this in a command prompt:
scoop bucket add extras
scoop install godot
eon-s commented 4 years ago

Windows package managers like Scoop are getting popular among devs, Godot is on Chocolatey too.

choco install godot
WolfGangsta commented 4 years ago

Gotcha. Thanks for the help! (And sorry for the late reply.)

I'll look into Scoop and Chocolatey--they look like just what I need to simplify things.

Calinou commented 3 years ago

To any of you experiencing this issue, does disabling Filesystem > On Save > Save Safe On Backup Then Rename in the Editor Settings improve the situaton?

Proksimas commented 3 years ago

Okay guys idk if this may help you but i tried to OC my processor so i installed 2 logiciel to monitoring my core: Intel Burn Cinebench from the store. After my OC i go on godot and i had the same error of you (the lacking permission) I uninstalled both software and that s work correctly. So maybe if you have a sofware who use some of tools on windows godot don't like this