diff options
author | hop311 <hop3114@gmail.com> | 2024-03-01 22:45:53 +0100 |
---|---|---|
committer | hop311 <hop3114@gmail.com> | 2024-03-01 22:45:53 +0100 |
commit | 3d216a129cf449c158188d65ce7cf70d507b4238 (patch) | |
tree | 2b6834c5ef1b6c8ec16a24a29f77a4330889f45b /src/openvic-simulation/types/IdentifierRegistry.hpp | |
parent | 164e76e367ff7dc5914f0d7105b5914fd3fba90a (diff) |
Identifier string_view invalidation fix
Diffstat (limited to 'src/openvic-simulation/types/IdentifierRegistry.hpp')
-rw-r--r-- | src/openvic-simulation/types/IdentifierRegistry.hpp | 10 |
1 files changed, 9 insertions, 1 deletions
diff --git a/src/openvic-simulation/types/IdentifierRegistry.hpp b/src/openvic-simulation/types/IdentifierRegistry.hpp index f1edc95..393ea37 100644 --- a/src/openvic-simulation/types/IdentifierRegistry.hpp +++ b/src/openvic-simulation/types/IdentifierRegistry.hpp @@ -194,7 +194,15 @@ namespace OpenVic { } items.emplace_back(std::move(item)); - identifier_index_map.emplace(std::move(new_identifier), StorageInfo::get_back_index(items)); + + const index_type index = StorageInfo::get_back_index(items); + + /* Get item's identifier via index rather than using new_identifier, as it may have been invalidated item's move. */ + identifier_index_map.emplace( + ValueInfo::get_identifier(ItemInfo::get_value(StorageInfo::get_item_from_index(items, index))), + StorageInfo::get_back_index(items) + ); + return true; } |