0000706: copy- paste- crash

This commit is contained in:
wmayer 2012-06-03 16:36:00 +02:00
parent 0623cd9b5e
commit 50a9ddee43
3 changed files with 23 additions and 15 deletions

View File

@ -130,12 +130,18 @@ void PropertyLink::Restore(Base::XMLReader &reader)
assert(getContainer()->getTypeId().isDerivedFrom(App::DocumentObject::getClassTypeId()) );
if (name != "") {
DocumentObject *pcObject = static_cast<DocumentObject*>(getContainer())->
getDocument()->getObject(name.c_str());
if (!pcObject)
DocumentObject* parent = static_cast<DocumentObject*>(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);

View File

@ -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

View File

@ -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 {