aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
author Hop311 <Hop3114@gmail.com>2024-03-01 23:07:32 +0100
committer GitHub <noreply@github.com>2024-03-01 23:07:32 +0100
commitc44e76b4f340bb9e667dca7afd7468c78b9de967 (patch)
tree2b6834c5ef1b6c8ec16a24a29f77a4330889f45b
parent164e76e367ff7dc5914f0d7105b5914fd3fba90a (diff)
parent3d216a129cf449c158188d65ce7cf70d507b4238 (diff)
Merge pull request #150 from OpenVicProject/identifier-name-fix
Identifier string_view invalidation fix
-rw-r--r--src/openvic-simulation/types/IdentifierRegistry.hpp10
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;
}