From 668ebd9be1785d6fd1ed9f7db0be0663749e373d Mon Sep 17 00:00:00 2001 From: Christoph Oelckers Date: Sat, 26 Sep 2020 20:36:10 +0200 Subject: [PATCH] - immediately abort loading a savegame if object deserialization fails. If the loader is allowed to go on, these objects will be linked into game structures and may do unpredictable things before the loader has a chance to abort at the end. --- src/common/engine/serializer.cpp | 1 + src/common/engine/serializer.h | 1 + src/p_saveg.cpp | 2 ++ 3 files changed, 4 insertions(+) diff --git a/src/common/engine/serializer.cpp b/src/common/engine/serializer.cpp index f0d31a13d..40c82dcab 100644 --- a/src/common/engine/serializer.cpp +++ b/src/common/engine/serializer.cpp @@ -675,6 +675,7 @@ void FSerializer::ReadObjects(bool hubtravel) { Printf(TEXTCOLOR_RED "Failed to restore all objects in savegame\n"); mErrors++; + mObjectErrors++; } } catch(...) diff --git a/src/common/engine/serializer.h b/src/common/engine/serializer.h index fe20f247b..3925eb86a 100644 --- a/src/common/engine/serializer.h +++ b/src/common/engine/serializer.h @@ -181,6 +181,7 @@ public: } int mErrors = 0; + int mObjectErrors = 0; }; FSerializer& Serialize(FSerializer& arc, const char* key, char& value, char* defval); diff --git a/src/p_saveg.cpp b/src/p_saveg.cpp index 4bf46e30f..d1b7a1ff6 100644 --- a/src/p_saveg.cpp +++ b/src/p_saveg.cpp @@ -956,6 +956,8 @@ void FLevelLocals::Serialize(FSerializer &arc, bool hubload) Thinkers.DestroyAllThinkers(); interpolator.ClearInterpolations(); arc.ReadObjects(hubload); + // If there have been object deserialization errors we must absolutely not continue here because scripted objects can do unpredictable things. + if (arc.mObjectErrors) I_Error("Failed to load savegame"); } arc("multiplayer", multiplayer);