Add a NOOP state to reduce logspam after error

This commit is contained in:
Henrik Rydgård 2022-12-02 13:28:06 +01:00
parent 52a684644d
commit f5a7661c51
5 changed files with 23 additions and 14 deletions

View file

@ -85,7 +85,8 @@ template<class T>
void DoVector(PointerWrap &p, std::vector<T> &x, T &default_val) {
u32 vec_size = (u32)x.size();
Do(p, vec_size);
x.resize(vec_size, default_val);
if (vec_size != x.size())
x.resize(vec_size, default_val);
if (vec_size > 0)
DoArray(p, &x[0], vec_size);
}

View file

@ -38,8 +38,8 @@ void DoMap(PointerWrap &p, M &x, typename M::mapped_type &default_val) {
x[first] = second;
--number;
}
break;
}
break;
case PointerWrap::MODE_WRITE:
case PointerWrap::MODE_MEASURE:
case PointerWrap::MODE_VERIFY:
@ -52,8 +52,10 @@ void DoMap(PointerWrap &p, M &x, typename M::mapped_type &default_val) {
--number;
++itr;
}
break;
}
break;
case PointerWrap::MODE_NOOP:
break;
}
}
@ -109,8 +111,8 @@ void DoMultimap(PointerWrap &p, M &x, typename M::mapped_type &default_val) {
x.insert(std::make_pair(first, second));
--number;
}
break;
}
break;
case PointerWrap::MODE_WRITE:
case PointerWrap::MODE_MEASURE:
case PointerWrap::MODE_VERIFY:
@ -122,8 +124,10 @@ void DoMultimap(PointerWrap &p, M &x, typename M::mapped_type &default_val) {
--number;
++itr;
}
break;
}
break;
case PointerWrap::MODE_NOOP:
break;
}
}

View file

@ -105,8 +105,10 @@ PointerWrapSection PointerWrap::Section(const char *title, int minVer, int ver)
if (!firstBadSectionTitle_) {
firstBadSectionTitle_ = title;
}
WARN_LOG(SAVESTATE, "Savestate failure: wrong version %d found for section '%s'", foundVersion, title);
SetError(ERROR_FAILURE);
if (mode != MODE_NOOP) {
WARN_LOG(SAVESTATE, "Savestate failure: wrong version %d found for section '%s'", foundVersion, title);
SetError(ERROR_FAILURE);
}
return PointerWrapSection(*this, -1, title);
}
return PointerWrapSection(*this, foundVersion, title);
@ -117,8 +119,9 @@ void PointerWrap::SetError(Error error_) {
error = error_;
}
if (error > ERROR_WARNING) {
// For the rest of this run, just measure.
mode = PointerWrap::MODE_MEASURE;
// For the rest of this run, do nothing, to avoid running off the end of memory or something,
// and also not logspam like MEASURE will do in an error case.
mode = PointerWrap::MODE_NOOP;
}
}

View file

@ -95,9 +95,10 @@ class PointerWrap
public:
enum Mode {
MODE_READ = 1, // load
MODE_WRITE, // save
MODE_MEASURE, // calculate size
MODE_VERIFY, // compare
MODE_WRITE, // save
MODE_MEASURE, // calculate size
MODE_VERIFY, // compare
MODE_NOOP, // don't do anything. Useful to cleanly doing stuff once we've hit an error.
};
enum Error {

View file

@ -1890,13 +1890,13 @@ void SavedataParam::DoState(PointerWrap &p) {
Do(p, saveDataListCount);
Do(p, saveNameListDataCount);
if (p.mode == p.MODE_READ) {
if (saveDataList != NULL)
if (saveDataList)
delete [] saveDataList;
if (saveDataListCount != 0) {
saveDataList = new SaveFileInfo[saveDataListCount];
DoArray(p, saveDataList, saveDataListCount);
} else {
saveDataList = NULL;
saveDataList = nullptr;
}
}
else