godot icon indicating copy to clipboard operation
godot copied to clipboard

FileAccess lock

Open jgestiot opened this issue 3 years ago • 1 comments

Godot version

v4.0.beta7.official.0bb1e89fb

System information

Windows 10 64 bits Vulkan API 1.2.0

Issue description

Relates to FileAccess. Attempts to re-read data from file with get_var() immediately after having saved it with store_var() fails (returns null). However, if the same operation is delayed without any change to the code, it works.

This led me to believe that the internal unlocking of the file takes time despite the fact that I assign null to the FileAccess handle before reopening the file since the function file.close() no longer exists.

The data saved is a smallish array of dictionaries (saved size about 3k). I checked the save file with an hex editor and all seems well.

Steps to reproduce

Create an array of dictionaries save it to file using store_var() close the file by assigning null to the FileAccess handle reopen the file (for reading) load the saved data with get_var() it returns null Repeat the same operation delaying reopening the file by using a Timer and it works

Minimal reproduction project

The issue is too basic to include code or a project. If needed I will supply the code.

jgestiot avatar Dec 04 '22 03:12 jgestiot

Similarly, with DirAccess

@tool
extends EditorScript

func _run():
	var f = FileAccess.open('hede',FileAccess.WRITE)
	f.store_string("hede")
	f.flush() # for good measure because of https://github.com/godotengine/godot/issues/68614#issuecomment-1316804845
	f = null
	print(DirAccess.remove_absolute("hede"))

will end with failure to delete the file. Interestingly, if this is run more than once, further iterations will print 0 even though the file is still not deleted in the end

oganm avatar Dec 06 '22 14:12 oganm