[Node] Safer node deletion
This commit is contained in:
parent
cf05da99a1
commit
14601ebd03
@ -199,28 +199,21 @@ namespace Components
|
|||||||
void Node::DeleteInvalidNodes()
|
void Node::DeleteInvalidNodes()
|
||||||
{
|
{
|
||||||
std::lock_guard<std::recursive_mutex> _(Node::NodeMutex);
|
std::lock_guard<std::recursive_mutex> _(Node::NodeMutex);
|
||||||
std::vector<Node::NodeEntry> cleanNodes;
|
|
||||||
|
|
||||||
for (auto node : Node::Nodes)
|
for (auto i = Node::Nodes.begin(); i != Node::Nodes.end();)
|
||||||
{
|
{
|
||||||
if (node.state == Node::STATE_INVALID && (Game::Sys_Milliseconds() - node.lastHeard) > NODE_INVALID_DELETE)
|
if (i->state == Node::STATE_INVALID && (Game::Sys_Milliseconds() - i->lastHeard) > NODE_INVALID_DELETE)
|
||||||
{
|
{
|
||||||
#if defined(DEBUG) && !defined(DISABLE_NODE_LOG)
|
#if defined(DEBUG) && !defined(DISABLE_NODE_LOG)
|
||||||
Logger::Print("Removing invalid node %s\n", node.address.getCString());
|
Logger::Print("Removing invalid node %s\n", i->address.getCString());
|
||||||
#endif
|
#endif
|
||||||
|
i = Node::Nodes.erase(i);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
cleanNodes.push_back(node);
|
++i;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (cleanNodes.size() != Node::Nodes.size())
|
|
||||||
{
|
|
||||||
//Node::Nodes.clear();
|
|
||||||
//Utils::Merge(&Node::Nodes, cleanNodes);
|
|
||||||
Node::Nodes = cleanNodes;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void Node::SyncNodeList()
|
void Node::SyncNodeList()
|
||||||
|
Loading…
Reference in New Issue
Block a user