Skip to content
Permalink
Browse files

fix possible double destruction when removing a group and its content…

… from document
  • Loading branch information...
wwmayer committed Jan 15, 2019
1 parent 71d57b3 commit 6e5369da3a31bfc7b2fd7723682acc1f091cb0ae
Showing with 14 additions and 0 deletions.
  1. +14 −0 src/App/GroupExtension.cpp
@@ -141,17 +141,31 @@ std::vector< DocumentObject* > GroupExtension::removeObjects(std::vector< Docume

void GroupExtension::removeObjectsFromDocument()
{
#if 1
while (Group.getSize() > 0) {
// Remove the objects step by step because it can happen
// that an object is part of several groups and thus a
// double destruction could be possible
const std::vector<DocumentObject*> & grp = Group.getValues();
removeObjectFromDocument(grp.front());
}
#else
const std::vector<DocumentObject*> & grp = Group.getValues();
// Use set so iterate on each linked object exactly one time (in case of multiple links to the same document)
std::set<DocumentObject*> grpSet (grp.begin(), grp.end());
for (std::set<DocumentObject*>::iterator it = grpSet.begin(); it != grpSet.end(); ++it) {
removeObjectFromDocument(*it);
}
#endif
}

void GroupExtension::removeObjectFromDocument(DocumentObject* obj)
{
// check that object is not invalid
if (!obj || !obj->getNameInDocument())
return;

// remove all children
if (obj->hasExtension(GroupExtension::getExtensionClassTypeId())) {
GroupExtension *grp = static_cast<GroupExtension*>(obj->getExtension(GroupExtension::getExtensionClassTypeId()));

0 comments on commit 6e5369d

Please sign in to comment.
You can’t perform that action at this time.