diff --git a/src/App/Document.cpp b/src/App/Document.cpp index 48ec6ea7b8..e119b97407 100644 --- a/src/App/Document.cpp +++ b/src/App/Document.cpp @@ -2691,15 +2691,14 @@ void Document::breakDependency(DocumentObject* pcObject, bool clear) link->setValues(std::vector()); } else { - // copy the list (not the objects) - std::vector linked = link->getValues(); - for (std::vector::iterator fIt = linked.begin(); fIt != linked.end(); ++fIt) { - if ((*fIt) == pcObject) { - // reassign the the list without the object to be deleted - linked.erase(fIt); - link->setValues(linked); - break; + const auto &links = link->getValues(); + if (std::find(links.begin(), links.end(), pcObject) != links.end()) { + std::vector newLinks; + for(auto obj : links) { + if (obj != pcObject) + newLinks.push_back(obj); } + link->setValues(newLinks); } } }