Is there a way to call the save method when the application crashes unplanned? #1601
-
I can make a backup once every certain interval, but is there a way to call the save method exactly when there is a failure? |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment
-
there is actually no way for you to save a state of an application or a specific section of data into file system when the application in question goes into a crash state, you cannot recover from this state (i.e. memory access violation which is the most common) so you can't go to the section of your code that's responsible for saving, what I suggest you do and is the best practice is to make a copy of the save file when you launch the game and when the original save file loads successfully as to prevent overwriting the backup with corrupted data, this way when your save gets corrupted because the app crashed during the saving process then you have the backup file to load when your original save file fails to load on launch. also don't keep the file open, when you want to save open the file, write your data, close the file, to reduce the chances of getting corruptions. it's also best to use ZLIB compression and AES encryption, this way you can store a variable in the save file with a specific hardcoded value, you then decompress and decrypt your data and when you don't find the specific hardcoded value you stored in your save file, you then know for sure your save file is corrupted. or you could discard all these problems and make your code not crash? i.e. handling edge cases and other stuff. about the interval you can instead use |
Beta Was this translation helpful? Give feedback.
there is actually no way for you to save a state of an application or a specific section of data into file system when the application in question goes into a crash state, you cannot recover from this state (i.e. memory access violation which is the most common) so you can't go to the section of your code that's responsible for saving, what I suggest you do and is the best practice is to make a copy of the save file when you launch the game and when the original save file loads successfully as to prevent overwriting the backup with corrupted data, this way when your save gets corrupted because the app crashed during the saving process then you have the backup file to load when your origin…