From 50a9ddee434719cedeb39d1ff8c1d43cd49af156 Mon Sep 17 00:00:00 2001 From: wmayer Date: Sun, 3 Jun 2012 16:36:00 +0200 Subject: [PATCH] 0000706: copy- paste- crash --- src/App/PropertyLinks.cpp | 14 ++++++++++---- src/Gui/MergeDocuments.cpp | 13 +++++-------- src/Gui/Tree.cpp | 11 ++++++++--- 3 files changed, 23 insertions(+), 15 deletions(-) diff --git a/src/App/PropertyLinks.cpp b/src/App/PropertyLinks.cpp index 6cc105808..9ffb1d033 100644 --- a/src/App/PropertyLinks.cpp +++ b/src/App/PropertyLinks.cpp @@ -130,12 +130,18 @@ void PropertyLink::Restore(Base::XMLReader &reader) assert(getContainer()->getTypeId().isDerivedFrom(App::DocumentObject::getClassTypeId()) ); if (name != "") { - DocumentObject *pcObject = static_cast(getContainer())-> - getDocument()->getObject(name.c_str()); - if (!pcObject) + DocumentObject* parent = static_cast(getContainer()); + DocumentObject* object = parent->getDocument()->getObject(name.c_str()); + if (!object) { Base::Console().Warning("Lost link to '%s' while loading, maybe " "an object was not loaded correctly\n",name.c_str()); - setValue(pcObject); + } + else if (parent == object) { + Base::Console().Warning("Object '%s' links to itself, nullify it\n",name.c_str()); + object = 0; + } + + setValue(object); } else { setValue(0); diff --git a/src/Gui/MergeDocuments.cpp b/src/Gui/MergeDocuments.cpp index 7addd29be..52713fa47 100644 --- a/src/Gui/MergeDocuments.cpp +++ b/src/Gui/MergeDocuments.cpp @@ -122,16 +122,13 @@ MergeDocuments::importObjects(std::istream& input) reader.readElement("Object"); std::string type = reader.getAttribute("type"); std::string name = reader.getAttribute("name"); - std::string docn = name; - - // remove number from end to avoid lengthy names - size_t lastpos = docn.length()-1; - while (docn[lastpos] >= 48 && docn[lastpos] <= 57) - lastpos--; - docn = docn.substr(0, lastpos+1); try { - App::DocumentObject* o = appdoc->addObject(type.c_str(),docn.c_str()); + // Use name from XML as is and do NOT remove trailing digits because + // otherwise we may cause a dependency to itself + // Example: Object 'Cut001' references object 'Cut' and removing the + // digits we make an object 'Cut' referencing itself. + App::DocumentObject* o = appdoc->addObject(type.c_str(),name.c_str()); objs.push_back(o); // use this name for the later access because an object with // the given name may already exist diff --git a/src/Gui/Tree.cpp b/src/Gui/Tree.cpp index ba3672d8c..c453662a5 100644 --- a/src/Gui/Tree.cpp +++ b/src/Gui/Tree.cpp @@ -830,9 +830,14 @@ void DocumentItem::slotChangeObject(const Gui::ViewProviderDocumentObject& view) children.insert(kt->second); QTreeWidgetItem* parent = kt->second->parent(); if (parent && parent != it->second) { - int index = parent->indexOfChild(kt->second); - parent->takeChild(index); - it->second->addChild(kt->second); + if (it->second != kt->second) { + int index = parent->indexOfChild(kt->second); + parent->takeChild(index); + it->second->addChild(kt->second); + } + else { + Base::Console().Warning("Gui::DocumentItem::slotChangedObject(): Object references to itself.\n"); + } } } else {