-
-
Notifications
You must be signed in to change notification settings - Fork 21.3k
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
File.StoreXXX methods do not flush on write (and there is no flush method) #29075
Comments
(Also relevant: #29043) |
Separate from Mono, there's probably scope to have a discussion on whether Godot should implement a |
Absolutely! Just to be clear, thats why I added both the |
I just saw a web project that simply saves a string followed by file close. Calling load right seemed to fetch the updated values but re-loading the tab then loading the value more often than not fails to get the updated value and pulls a previously persisted value. If you waited 10 seconds or more before clicking refresh it would "usually' work but still wasn't reliable. Edit: This seems like a behaviour that would reflect a typical flush wasn't being called but there isn't one to call in godot |
I had another use-case today to write log files, so I've been looking at this again.
Both encrypted and compressed implementations do not support flushing. They are both designed having their content written to a buffer, and then on close the buffer is written to disk in either the compressed or encrypted format. FileAccessNetwork also has no concept of flushing. The behaviour of each seems to vary - encrypted and compressed both silently ignore the flush operation, whilst network will error. Any work on this should probably make the behaviours consistent as part of the change. My preference would be to expose the Alternatively we could leave as is, and encourage developers to use |
Wrong button ^^ |
The use-case is all file systems operations MUST either work every time or return an error. I've been chasing this problem for days. My game allows the player to save the current state and exit. The save works intermittently if the player exits the game (or web page) quickly. It is especially bad on HTML5 exports (tried multiple browsers - same behavior). Have experienced the same problem with Android app also. We really need the ability to flush file operations manually because the automatic cache flush is unreliable in real world applications. Code:
|
I have a web export running on an IP restricted site that demonstrates the problem. If someone wants to see the problem first hand, please email maps.erpiv at homebuilt-lan.com with the IP you'll use to access the site and I'll add it to the authorized list then send you the URL for the game. To Reproduce:
If you see the main page then the player data saved did not get flushed. Repeat the above except wait 10 seconds before closing the browser. When you browse to the site again you'll see the Resume/Discard scene. For what it's worth, if you discard this time and immediately close the browser, the saved state will still be there when you re-enter the game. Discard then wait 10 seconds before closing the browser and the saved game state will be gone. Thanks! |
I've put further work on my game on hold until this problem is solved. I can't publish it if the game_state save feature is unreliable. Suggestion: Rather than expose a flush() method, add a synchronous_write property to File and Directory that forces an immediate flush on all write operations. It can default to False. Add a warning to the docs about performance impact when synchronous write is used. Thank you! |
See also godotengine/godot-proposals#1912. Edit: I opened a pull request to expose a |
This can be used to ensure a file has its contents saved even if the project crashes or is killed by the user (among other use cases). See discussion in godotengine#29075.
This can be used to ensure a file has its contents saved even if the project crashes or is killed by the user (among other use cases). See discussion in godotengine#29075. (cherry picked from commit ab39746)
Godot version:
3.1.1 (Mono)
OS/device including version:
Windows 10
Issue description:
When calling the store methods of
file
, e.gstore_string(...)
the content is not automatically flushed. There is also no method to do it manually instead. If the application is killed (GDScript), or even worse under Mono, just graceful exited, the unflushed content will not be written.Closing the file before exit correctly persist the writes.
The GDScript implementation has decent cleanup and will close open files on application exit, and this will flush the contents. If you kill the application, rather than doing a graceful close, then the content will not be written.
Under Mono the behaviour is worse. You can simply close the application (e.g by clicking the X), and the un-flushed data will be lost.
Steps to reproduce:
(Mono)
File
classStoreString
methodMinimal reproduction project:
Project includes GDScript and Mono versions for testing. Just attach whichever script version you need.
Testing-FileFlush.zip
The text was updated successfully, but these errors were encountered: