From d4f8453c2294b37d6f888f7d7a69f83437bd137e Mon Sep 17 00:00:00 2001 From: Peter Nelson Date: Wed, 6 Nov 2024 13:51:26 +0000 Subject: [PATCH] Codefix: Clear and reserve storage when loading vectors from savegames. --- src/saveload/saveload.cpp | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/src/saveload/saveload.cpp b/src/saveload/saveload.cpp index 75681fc548..1a8361ff3f 100644 --- a/src/saveload/saveload.cpp +++ b/src/saveload/saveload.cpp @@ -1297,6 +1297,11 @@ public: default: NOT_REACHED(); } + list->clear(); + if constexpr (std::is_same_v>) { + list->reserve(length); + } + /* Load each value and push to the end of the storage. */ for (size_t i = 0; i < length; i++) { Tvar &data = list->emplace_back();