Why do saves/ video files get corrupted?


So when a save file is corrupted, what is the reasoning behind it? Is it a software issue or hardware? Im guessing there are an unknown number of reasons, but it always made me think why.

In: 11

Any file on a computer can become corrupt, but in general files that are getting written to frequently are more susceptible. And anything that interrupts that file writing is just asking for it to be bork. Turning your game console off in the middle of a checkpoint or a gamesave is a great example. There’s all sorts of low level filesystem safeguards to minimize this, but nothing is perfect.

An example: storage is divided into small logical units called blocks. How big they are depends on OS and filesystem, but lets say they’re 1k or 1024 bytes. You create a new empty game save and you haven’t done anything yet, so the first few bytes are some file header stuff (what game, your user name), some bytes that represent your starting inventory and your location and then some bytes that mark end of file. This doesn’t take anywhere close to 1024 bytes so the “end of file” is well before the end of the block.

For error correction usually some checksum on all the data in the file is calculated and also written to the end of the file. If the contents of the file are read and don’t match the checksum, then its “corrupt”.

When your gamesave extends past the space in a single block, the last few bytes of that block are a pointer to the next block in the file aka “continued … over there -> block123” and over in block123 the bytes of game data continue. Rinse and repeat.

Now lets say either a software bug or a hardware issue (power button, power goes off) right when we’re modifying the gamesave. Maybe you just picked up some loot so we have to extend the file by a block. Its just allocated the new block and has written the pointer to it at the end of the old block, but hasn’t written any content in the new block yet. When the file is read again, there’s no content, no checksum, no end of file in the last block. Gamesave corrupt.

There’s numerous ways the game or the operating system or the hardware/power/user can mess up the writing of a file, this is just one possible way.

A bunch of reasons. Software errors, hardware errors, user error (ie turning it off while saving), cosmic rays flipping bits… The only thing to prevent save and video loss is backing up multiple times in different locations.

Not exactly an answer to your question, but MattKC, a YouTuber I follow, just posted a [video](https://www.youtube.com/watch?v=Nwjypk1933U) last week about fixing a corrupted Playstation 2 save file this past week. If you don’t understand anything about checksums and don’t have at least a vague idea of how data is written to disks, it might be over your head, but I don’t think that he gets too far into the weeds. It’s a pretty interesting video that addresses one particular scenario of save data corruption (in this case, it happened because a game crashed while it was autosaving).

In modern hardware you have to try really hard (or really, REALLY often) to corrupt a file. From the software perspective however, things are a lot less stable. Video games are developed fast, and almost every one of them needs their own saving/loading logic, so there is little reusability.

As soon as a game’s saved state grows in complexity, the odds of edge cases increases drastically. Edge cases are the bane of QA, and it is theoretically impossible to account for all of them.

So add one to the other, and you get a variety of games that currently have saving and loading code that did not account for particular edge cases. When those situations arise, the saving logic doesn’t write the game’s state properly, or the loading logic does not recognize a state that may have been valid outside of the edge case.

TLDR: Lots of games, little time for QA -> bugs.

Usually it’s a software issue. Some kind of error or bug in the saving process stops the new file from being made correctly, but the old file has already been deleted. Or the save file might be good but some kind of bug in the *loading* process causes it to be useless.