OpenNBS / OpenNoteBlockStudio

An open-source Minecraft music maker.
https://opennbs.org/
MIT License
743 stars 51 forks source link

[CRITICAL] Autosave does not correctly save NBS files on the latest build (v3.11 beta 2) #460

Open CreeperPookie opened 1 month ago

CreeperPookie commented 1 month ago

Describe the bug After updating to the latest build I noticed some of my NBS files were mysteriously vanishing; at first, I thought this was probably some problem with my computer but even after fresh installing Windows I was still getting this problem (had to do with another issue)

To Reproduce Steps to reproduce the behavior:

  1. Open any song on the latest build, and make sure autosave is enabled
  2. Make unsaved changes to the song, but don't manually save
  3. Wait for autosave to attempt to "save" the changes
  4. Note how even at 0 minutes remaining to auto save it does not save the file, and will even continue to tick lower into the negatives

Expected behavior The expected behavior would be the same as what OpenNBS did in the previous builds, or to save normally when the autosave counter hits 0; and to reset the counter when autosaving.

Screenshots This is a screenshot of a NBS window with the counter and being at in incorrect state, and with window title too so the unsaved marker * is also visible. image

Additional context If it were just a simple autosave bug I wouldn't consider this as so important; the problem is that in this state it kind of literally unsaves the actual file, and you may be able to see this if you open an explorer window in the folder the NBS file is saved in; for me it literally blinks in and out of existance as if it was being deleted and being recreated. Even worse, I've personally experienced the file being completely deleted because of this for at least 2 different NBS files; I don't know why the files get removed, especially as saving doesn't usually imply deleting the file, but in either case this makes the current build very unsafe to use, which might especially be true if you listen to songs in edit mode. I did test v3.10.0 and I can confirm autosave works normally; however I did test v3.10.0 beta 1 and I can confirm it also has this bug too.

Bentroen commented 1 month ago

Thanks for reporting the issue!

This is the bit of logic that actually saves the file when the auto-save counter drops to 0: https://github.com/OpenNBS/OpenNoteBlockStudio/blob/v3.11.0-beta.2/scripts/control_draw/control_draw.gml#L88-L92

The problem at play here is that the auto-save counter is never reset once the file is actually saved. So the counter keeps ticking down and, due to the <= bit at the logic above, the file gets saved to disk 60 times per second (or whatever your FPS setting happens to be set to).

This line: https://github.com/OpenNBS/OpenNoteBlockStudio/blob/v3.11.0-beta.2/scripts/save_song/save_song.gml#L124 is not being run for some reason, which is the culprit. I'll make sure to investigate this for the next 3.11 beta.

Bentroen commented 1 month ago

The bug was introduced in commit 52144ea. Auto-save now saves the file in "backup mode" which saves the file silently, without adding it to recent songs and without resetting the auto-save timer. Should be an easy fix :)