Skip to content

Commit

Permalink
fix possible double destruction when removing a group and its content…
Browse files Browse the repository at this point in the history
… from document
  • Loading branch information
wwmayer committed Jan 15, 2019
1 parent 71d57b3 commit 6e5369d
Showing 1 changed file with 14 additions and 0 deletions.
14 changes: 14 additions & 0 deletions src/App/GroupExtension.cpp
Expand Up @@ -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()));
Expand Down

0 comments on commit 6e5369d

Please sign in to comment.