Zylann / godot_voxel

Voxel module for Godot Engine
MIT License
2.68k stars 251 forks source link

`VoxelStreamSQLite` is missing chunks when loads #597

Open matthewhilton opened 9 months ago

matthewhilton commented 9 months ago

Describe the bug When loading a stream from VoxelStreamSQLite, there are missing chunks in the save:

Possibly related to https://github.com/Zylann/godot_voxel/issues/596

To Reproduce Use this example project: VoxelSaveLoadTestSQLite.zip

  1. Change the VoxelStreamSQLite directory to somewhere on your computer
  2. Start the game, and press 'E' this will generate a big cube
  3. Press 'R' and check the console output, it will save the SQLite db
  4. Reload the game
  5. The SQLite DB is loaded, but there are missing chunks

Expected behavior There shouldn't be missing chunks in the loaded edits.

Screenshots The saved edit: image

The loaded edit from the SQLite DB: image

Environment

Zylann commented 9 months ago

I changed the path to be just save3.sqlite so it saves next to the game. I did a first test and the cube loaded properly. I tested several more times, still could not reproduce.

As mentionned in https://github.com/Zylann/godot_voxel/issues/596#issuecomment-1925840311, my only suspicions are that saving didnt finish when you closed the game, and/or you closed the game by killing it instead of using regular closing. In addition, the SQLite stream uses a cache to batch saves because they can be quite slow if done individually. That cache is normally flushed when full or when the resource is destroyed (when the game closes normally or nothing else references it), but won't have the opportunity to get flushed if you kill the game, even if all saving tasks are done. So indeed, if I use the Stop button of the editor (which kills the game with no chance of cleanup), chunks go missing, which is currently expected. (cache flushing has been patched in 75f92419801e76f36e1b3dcd9f5d025c44bd58f2)

Note: in this project, you have run_stream_in_editor turned on. That means if the scene is open, the save file will be held open and can't be deleted until the scene is closed. There can also be writing conflicts if both the editor and the game try to write into it. That didn't seem to prevent the game from loading or saving, but in order to reproduce I had to close the scene file so I could delete the save.

https://github.com/Zylann/godot_voxel/assets/1311555/33e9369c-3191-4715-9678-12b55bd2779f