diff --git a/src/dusk/save/save.c b/src/dusk/save/save.c index 4586b0af..bc7ae1ce 100644 --- a/src/dusk/save/save.c +++ b/src/dusk/save/save.c @@ -9,6 +9,7 @@ #include "util/memory.h" #include "assert/assert.h" #include "rpg/cutscene/cutscenesystem.h" +#include "console/console.h" save_t SAVE; @@ -186,10 +187,18 @@ errorret_t saveSaveSettings() { errorret_t saveLoadSettings() { assertTrue(SAVE.deviceCurrent != 0xFF, "No current device"); - errorChain(saveDeviceSettingsRead( + errorret_t ret = saveDeviceSettingsRead( &SAVE.devices[SAVE.deviceCurrent], &SAVE.settings - )); + ); + if(errorIsNotOk(ret)) { + // Corrupt or incompatible (e.g. wrong/missing schema version) settings + // file - don't take the whole game down over it, just reset to + // defaults and carry on. + errorCatch(errorPrint(ret)); + consolePrint("Settings file could not be loaded, resetting to defaults.\n"); + saveSettingsInit(&SAVE.settings); + } SAVE.settingsDirty = false; errorOk(); @@ -222,12 +231,24 @@ errorret_t saveLoadSlot() { errorOk(); } - errorChain(saveDeviceSlotRead( + errorret_t ret = saveDeviceSlotRead( &SAVE.devices[SAVE.deviceCurrent], &SAVE.slot, SAVE.slotCurrent - )); - + ); + if(errorIsNotOk(ret)) { + // Corrupt or incompatible (e.g. wrong/missing schema version) slot + // file - don't take the whole game down over it, treat it the same as + // an empty/unused slot. + errorCatch(errorPrint(ret)); + consolePrint( + "Save slot %u could not be loaded, treating as empty.\n", + (uint32_t)SAVE.slotCurrent + ); + saveSlotInit(&SAVE.slot); + } + + // Update cache SAVE.caches[SAVE.slotCurrent] = SAVE.slot.cachedData; SAVE.slotDirty = false;