From ddae078b3a8b7c7ec9d1d8bb06e9cfa1da5fab1e Mon Sep 17 00:00:00 2001 From: zeromus Date: Thu, 14 Aug 2008 07:50:41 +0000 Subject: [PATCH] restore savestate error recovery functionality. This should have the side effect of guaranteeing that ( SF [ 2040761 ] Wrong savestate bug - crashes FCEUX) is resolved. [[Split portion of a mixed commit.]] --- changelog.txt | 1 + src/state.cpp | 10 ++++++++++ 2 files changed, 11 insertions(+) diff --git a/changelog.txt b/changelog.txt index 4b9390a7..e73e108b 100644 --- a/changelog.txt +++ b/changelog.txt @@ -1,5 +1,6 @@ ---version 2.0.2 released--- +14-aug-2008 - zeromus - restore savestate error recovery functionality. This should have the side effect of guaranteeing that ( SF [ 2040761 ] Wrong savestate bug - crashes FCEUX) is resolved. 14-aug-2008 - zeromus - SF [ 2047001 ] Low speeds crash FCEUX 14-aug-2008 - zeromus - SF [ 2050371 ] FCM>FM2 converter should release file handle 13-aug-2008 - zeromus - restore ungzipping (and unzipping in sdl) capability which was lost when archive support was added diff --git a/src/state.cpp b/src/state.cpp index cae7e98f..dedb0bac 100644 --- a/src/state.cpp +++ b/src/state.cpp @@ -548,6 +548,12 @@ int FCEUSS_LoadFP_old(std::istream* is, ENUM_SSLOADPARAMS params) bool FCEUSS_LoadFP(std::istream* is, ENUM_SSLOADPARAMS params) { + //maybe make a backup savestate + memorystream msBackupSavestate; + bool backup = (params == SSLOADPARAM_BACKUP); + if(backup) + FCEUSS_SaveMS(&msBackupSavestate,Z_NO_COMPRESSION); + uint8 header[16]; //read and analyze the header @@ -558,6 +564,7 @@ bool FCEUSS_LoadFP(std::istream* is, ENUM_SSLOADPARAMS params) FCEU_state_loading_old_format = true; bool ret = FCEUSS_LoadFP_old(is,params)!=0; FCEU_state_loading_old_format = false; + if(!ret && backup) FCEUSS_LoadFP(&msBackupSavestate,SSLOADPARAM_NOBACKUP); return ret; } @@ -578,6 +585,7 @@ bool FCEUSS_LoadFP(std::istream* is, ENUM_SSLOADPARAMS params) int error = uncompress((uint8*)&buf[0],&uncomprlen,(uint8*)&cbuf[0],comprlen); if(error != Z_OK || uncomprlen != totalsize) return false; + //we dont need to restore the backup here because we havent messed with the emulator state yet } else { @@ -604,6 +612,8 @@ bool FCEUSS_LoadFP(std::istream* is, ENUM_SSLOADPARAMS params) x=FCEUMOV_PostLoad(); } + if(!x && backup) FCEUSS_LoadFP(&msBackupSavestate,SSLOADPARAM_NOBACKUP); + return x; }