From 4bbc4228b64c76620e36ab53087eee13ff8c4a76 Mon Sep 17 00:00:00 2001 From: Ivan Mogilko Date: Fri, 27 Oct 2023 01:41:21 +0300 Subject: [PATCH] Engine: fixed Overlay bitmap order read from legacy saves --- Engine/game/savegame_v321.cpp | 16 ++++++---------- 1 file changed, 6 insertions(+), 10 deletions(-) diff --git a/Engine/game/savegame_v321.cpp b/Engine/game/savegame_v321.cpp index 117f5575f99..b6653c00a3d 100644 --- a/Engine/game/savegame_v321.cpp +++ b/Engine/game/savegame_v321.cpp @@ -350,10 +350,9 @@ static void restore_game_ambientsounds(Stream *in, RestoredData &r_data) } } -static void ReadOverlays_Aligned(Stream *in, std::vector &has_bitmap, size_t num_overs) +static void ReadOverlays_Aligned(Stream *in, std::vector &has_bitmap, size_t num_overs) { AlignedStream align_s(in, Common::kAligned_Read); - has_bitmap.resize(num_overs); // Remember that overlay indexes may be non-sequential auto &overs = get_overlays(); for (size_t i = 0; i < num_overs; ++i) @@ -365,12 +364,10 @@ static void ReadOverlays_Aligned(Stream *in, std::vector &has_bitmap, size if (over.type < 0) continue; // safety abort if (overs.size() <= static_cast(over.type)) - { overs.resize(over.type + 1); - has_bitmap.resize(over.type + 1); - } overs[over.type] = std::move(over); - has_bitmap[over.type] = has_bm; + if (has_bm) + has_bitmap.push_back(over.type); } } @@ -381,11 +378,10 @@ static void restore_game_overlays(Stream *in, RestoredData &r_data) // the vector may be resized during read auto &overs = get_overlays(); overs.resize(num_overs); - std::vector has_bitmap(num_overs); + std::vector has_bitmap; ReadOverlays_Aligned(in, has_bitmap, num_overs); - for (size_t i = 0; i < overs.size(); ++i) { - if (has_bitmap[i]) - r_data.OverlayImages[i].reset(read_serialized_bitmap(in)); + for (auto over_id : has_bitmap) { + r_data.OverlayImages[over_id].reset(read_serialized_bitmap(in)); } }