I have have setup code to save the game-state to the disk. However if the game crashes before a save is done, then the game progress would be lost. Can anyone suggest a way to execute a game-save, when the game has crashed?
Hey @somawheels.
Unfortunately, no, there really isn’t. A crash means no functionality may execute any longer. This is actually why I am a big advocate for auto-saves having more than one slot, and many reasons to do so, because often a save crash will repeat when loading, as well. Not even the big, bad, AAA game companies can get around that, unfortunately.
Actually there is one game that has figured it out (modded at least) Minecraft I have no clue how they do it but there’s a mod that detects a crash is happening and gathers the error codes locks the world rewinds it to before the crash saves it then spits out the error on screen and in the log after closing the game it’s wild I still haven’t been able to figure out how they do it but it does work I forced crashed it many times and the after save is never corrupted
There is probably a try catch statement that handles the exception in minecraft.
I was thinking you just need a thread that is separate to the game process. So when the game process ends, that thread still hangs around and does it’s saving.
The thread would still need a process running as the process would be handling memory. And if you ran multiple concurrent threads on one process, you can run into race conditions and still fail (let alone fail anyway once the process exits). Now if you wanted to run 2 processes at once, it begs many more questions, with one being how you would communicate between both processes (especially after 1 fails and exits) given how each OS has different implementations. Shared memory has its own complications as well (especially if memory is cached).