diff --git a/src/frontend/UiDocument.cpp b/src/frontend/UiDocument.cpp index da4fec51..c1269b87 100644 --- a/src/frontend/UiDocument.cpp +++ b/src/frontend/UiDocument.cpp @@ -45,7 +45,7 @@ std::shared_ptr UiDocument::get(const std::string& id) const { if (found == map.end()) { return nullptr; } - return found->second; + return found->second.lock(); } const uidocscript& UiDocument::getScript() const { diff --git a/src/frontend/UiDocument.hpp b/src/frontend/UiDocument.hpp index 2ad00da8..8ebf7c3e 100644 --- a/src/frontend/UiDocument.hpp +++ b/src/frontend/UiDocument.hpp @@ -19,7 +19,7 @@ struct uidocscript { bool onclose : 1; }; -using UINodesMap = std::unordered_map>; +using UINodesMap = std::unordered_map>; class UiDocument { std::string id; diff --git a/src/graphics/ui/elements/UINode.cpp b/src/graphics/ui/elements/UINode.cpp index f61e61a9..e62ff1df 100644 --- a/src/graphics/ui/elements/UINode.cpp +++ b/src/graphics/ui/elements/UINode.cpp @@ -385,11 +385,14 @@ bool UINode::isSubnodeOf(const UINode* node) { void UINode::getIndices( const std::shared_ptr& node, - std::unordered_map>& map + std::unordered_map>& map ) { const std::string& id = node->getId(); if (!id.empty()) { - map[id] = node; + const auto& found = map.find(id); + if (found == map.end() || found->second.expired()) { + map[id] = node; + } } auto container = std::dynamic_pointer_cast(node); if (container) { diff --git a/src/graphics/ui/elements/UINode.hpp b/src/graphics/ui/elements/UINode.hpp index 011c2367..cbd43b38 100644 --- a/src/graphics/ui/elements/UINode.hpp +++ b/src/graphics/ui/elements/UINode.hpp @@ -289,7 +289,7 @@ namespace gui { /// @brief collect all nodes having id static void getIndices( const std::shared_ptr& node, - std::unordered_map>& map + std::unordered_map>& map ); static std::shared_ptr find(