Save files that seem safe become corrupt after system unexpected shutdown.

Player setup Saves & Loading
SeirVed [github] · 4 months ago

Issue description

Save files that get made between multiple game sessions are still at risk of becoming 'corrupt' if PC is hard reset.
What is the point of uploading to steam cloud if they are broken?
What is the point in adding checksum if it fails to protect saves?
Please provide a way to extract or recover savegames.

The game failed to initialize. If this issue persists, please file a bug report.

System.IO.IOException: Corrupted data ReadInternal
  at System.IO.Compression.DeflateStreamNative.CheckResult (System.Int32 result, System.String where) [0x000a0]  
  at System.IO.Compression.DeflateStreamNative.ReadZStream (System.IntPtr buffer, System.Int32 length) [0x0000e]  
  at System.IO.Compression.DeflateStream.ReadInternal (System.Byte[] array, System.Int32 offset, System.Int32 count) [0x00027]  
  at System.IO.Compression.DeflateStream.Read (System.Byte[] array, System.Int32 offset, System.Int32 count) [0x00071]  
  at System.IO.Compression.GZipStream.Read (System.Byte[] array, System.Int32 offset, System.Int32 count) [0x00006]  
  at Mafi.Serialization.BufferedReadStream.fillBuffer () [0x00007]  
  at Mafi.Serialization.BufferedReadStream.Read (System.Byte[] buffer, System.Int32 offset, System.Int32 count) [0x000b8]  
  at System.IO.BinaryReader.FillBuffer (System.Int32 numBytes) [0x00061]  
  at System.IO.BinaryReader.ReadUInt64 () [0x00000]  
  at Mafi.Serialization.BlobReader.ReadULongNonVariable () [0x00000]  
  at Mafi.Core.SaveGame.GameLoader.continueLoadUntilHeader (Mafi.Serialization.BlobReader reader, System.UInt64 finalReadHeader, Mafi.Collections.ImmutableCollections.ImmutableArray`1[Mafi.Core.SaveGame.ModInfoRaw]& modsInfo, Mafi.Core.SaveGame.GameSaveInfo& saveInfo, Mafi.Collections.ImmutableCollections.ImmutableArray`1[Mafi.Core.Game.IConfig]& configs) [0x00018]  
  at Mafi.Core.SaveGame.GameLoader.TryLoadMods_MayThrow (System.IO.Stream stream, System.Int32& saveVersion) [0x00019]  
  at Mafi.Core.SaveGame.ModHelper.LoadModsFromSaveFile (Mafi.Core.IFileSystemHelper fsHelper, Mafi.Core.SaveFileInfo saveInfo, Mafi.Option`1[Mafi.Core.SaveGame.LoadFailInfo]& errorOnFileLoad) [0x000ac]  

Game version: 0.8.4b
Loaded mods: none
Failed mods: none

:D

Reproduction steps

Play game,
Save a few times, open and close game, whatever.
Turn off PC via power.

Saves are broke

Game version and build number

0.8.4 b593

Operating system

Windows

Attachments

26-06-01_17-18-30_6620.log

oopies.save

2 attachments only for registered users
SeirVed [github] · 4 months ago

26-06-06_03-40-autosave-paused.save, 26-06-06_02-36-autosave-paused.save, LEGS.save, 26-06-06_01-05-autosave-paused.save, 26-06-06_00-44-autosave-paused.save, LAST_WORKING.save

I did a byte-level comparison between several affected .save files and two saves that still load correctly. The working saves have the normal MaFiSave-style header followed immediately by a gzip stream at offset 40 (1F 8B...) and can be decompressed successfully; for example, FG.save decompresses to about 22.6 MB, and 26-06-06_00-27-autosave-paused.save decompresses to about 26.3 MB. The broken saves are different: most of them still have a plausible 40-byte save header, but every byte after that is 00; one file was entirely zeroed. So these do not look like ordinary checksum mismatches where the data is present but the checksum is stale. They look like preallocated/header-written save files where the compressed payload was never written, or was replaced with zeroes during/after an unexpected shutdown. In that state the checksum is correctly detecting failure, but there is no recoverable game data left inside the file. It would probably help if saving used a stricter atomic pattern: write the full save to a temporary file, flush/fsync it, verify it, then replace the previous known-good save only after the new file is complete; ideally also preserve at least one previous known-good autosave instead of letting a zero-body save replace it.

6 attachments only for registered users
14 Showing 1–2 of 2