add a guard for trading entity servers by checking node count

This commit is contained in:
Stephen Birarda 2017-03-16 18:41:26 -07:00
parent c63a2c9cda
commit 0a118bd268

View file

@ -326,7 +326,26 @@ void EntityScriptServer::nodeActivated(SharedNodePointer activatedNode) {
void EntityScriptServer::nodeKilled(SharedNodePointer killedNode) {
switch (killedNode->getType()) {
case NodeType::EntityServer: {
clear();
// Before we clear, make sure this was our only entity server.
// Otherwise we're assuming that we have "trading" entity servers
// (an old one going away and a new one coming onboard)
// and that we shouldn't clear here because we're still doing work.
bool hasAnotherEntityServer = false;
auto nodeList = DependencyManager::get<NodeList>();
nodeList->eachNodeBreakable([&hasAnotherEntityServer, &killedNode](const SharedNodePointer& node){
if (node->getType() == NodeType::EntityServer && node->getUUID() != killedNode->getUUID()) {
// we're talking to > 1 entity servers, we know we won't clear
hasAnotherEntityServer = true;
return false;
}
return true;
});
if (hasAnotherEntityServer) {
clear();
}
break;
}