SVN commit 669724 by staikos: more checks and cleanup, and add a copy constructor to indicate where Kst will crash due to shallow copy of pointers. This is really nasty and took hours to track down. It may also affect trunk, but I don't know of any place doing this particular thing in trunk. M +13 -9 kstobjectcollection.h --- branches/work/kst/portto4/kst/src/libkst/kstobjectcollection.h #669723:669724 @@ -75,6 +75,7 @@ class KstObjectCollection { public: KstObjectCollection(); + KstObjectCollection(const KstObjectCollection& copy) { qDebug() << "CRASH! Deep copy required."; } ~KstObjectCollection(); typedef typename KstObjectList >::const_iterator const_iterator; @@ -193,11 +194,11 @@ template KstObjectTreeNode *KstObjectTreeNode::child(const QString& tag) const { - if (_children.contains(tag)) { - return _children[tag]; - } else { - return NULL; + typename QMap *>::ConstIterator i = _children.find(tag); + if (i != _children.end()) { + return *i; } + return 0; } @@ -245,12 +246,15 @@ nextNode->_parent = currNode; currNode->_children[*i] = nextNode; if (index) { - QList *> *l; - if (!(l = index->take(*i))) { + QList *> *l = 0; + typename KstObjectNameIndex::Iterator it = index->find(*i); + if (it == index->end()) { l = new QList *>; + index->insert(*i, l); + } else { + l = *it; } l->append(nextNode); - index->insert(*i, l); } } currNode = nextNode; @@ -756,7 +760,8 @@ // recursion helper template void KstObjectCollection::relatedNodesHelper(T *o, KstObjectTreeNode *n, QHash* >& nodes) { - + Q_ASSERT(o); + Q_ASSERT(n); if (n->object() && n->object() != o && !nodes.contains((long)n)) { #if NAMEDEBUG > 2 qDebug() << "Found related node to" << o->tag().tagString() << ":" << n->object()->tag().tagString(); @@ -795,7 +800,6 @@ for (QStringList::ConstIterator i = ft.begin(); i != ft.end(); ++i) { typename KstObjectNameIndex::ConstIterator ni = _index.find(*i); - qDebug() << "Iterate" << *i; if (ni != _index.end()) { QList *> *nodeList = *ni; for (typename QList *>::ConstIterator i2 = nodeList->begin(); i2 != nodeList->end(); ++i2) {