Skip to content

Commit

Permalink
[Core] assure uniqueness for new node guid (synfig#2029)
Browse files Browse the repository at this point in the history
(cherry picked from commit 2f18910)
  • Loading branch information
rodolforg authored and ice0 committed Feb 28, 2021
1 parent 1465f2a commit a6e8ee9
Showing 1 changed file with 9 additions and 4 deletions.
13 changes: 9 additions & 4 deletions synfig-core/src/synfig/node.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -82,13 +82,15 @@ namespace {
return i == map.end() ? nullptr : i->second;
}

void add(const GUID &guid, Node *node) {
bool add(const GUID &guid, Node *node) {
assert(guid);
assert(node);

std::lock_guard<std::mutex> lock(mutex);
assert(!map.count(guid));
if (map.count(guid) > 0)
return false;
map[guid] = node;
return true;
}

void remove(const GUID &guid, Node *node) {
Expand Down Expand Up @@ -221,8 +223,11 @@ Node::get_guid()const
std::lock_guard<std::mutex> lock(guid_mutex_);
if(!guid_)
{
guid_.make_unique();
global_node_map().add(guid_, const_cast<Node*>(this));
bool added = false;
do {
guid_.make_unique();
added = global_node_map().add(guid_, const_cast<Node*>(this));
} while (!added);
}
return guid_;
}
Expand Down

0 comments on commit a6e8ee9

Please sign in to comment.