From: joncruz Date: Sun, 14 May 2006 07:21:09 +0000 (+0000) Subject: Corrected base structure and avoiding infinite loop. X-Git-Url: https://git.tokkee.org/?a=commitdiff_plain;h=0832343fd7f087d3b718bc86f2cf74014e56b582;p=inkscape.git Corrected base structure and avoiding infinite loop. --- diff --git a/ChangeLog b/ChangeLog index f2d8b0dd5..cdf959df9 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,8 @@ +2006-05-14 Jon A. Cruz + + * src/document-subset.cpp, src/layer-manager.h, src/layer-manager.cpp: + Corrected base structure and avoiding infinite loop. + 2006-05-14 Michael Wybrow * src/widgets/toolbox.cpp: Slightly increase size of the diff --git a/src/document-subset.cpp b/src/document-subset.cpp index 217176f4e..4e7e9f694 100644 --- a/src/document-subset.cpp +++ b/src/document-subset.cpp @@ -57,17 +57,32 @@ struct DocumentSubset::Relations : public GC::Managed, } else { Siblings::const_iterator first=children.begin(); Siblings::const_iterator last=children.end() - 1; - while ( first != last ) { - Siblings::const_iterator mid=first + ( last - first + 1 ) / 2; - int pos=sp_object_compare_position(*mid, obj); + if ( children.size() == 1 ) { + int pos = sp_object_compare_position(*first, obj); if ( pos < 0 ) { - first = mid; + // All good. } else if ( pos > 0 ) { - last = mid; + last++; } else { g_assert_not_reached(); } + } else { + while ( first != last ) { + Siblings::const_iterator mid=first + ( last - first + 1 ) / 2; + int pos=sp_object_compare_position(*mid, obj); + if ( pos < 0 ) { + first = mid; + } else if ( pos > 0 ) { + if ( last == mid ) { + break; + } + last = mid; + } else { + g_assert_not_reached(); + } + } } + return last - children.begin(); } } diff --git a/src/layer-manager.cpp b/src/layer-manager.cpp index 01af95424..15bd57fd9 100644 --- a/src/layer-manager.cpp +++ b/src/layer-manager.cpp @@ -22,8 +22,18 @@ namespace Inkscape { LayerManager::LayerManager(SPDesktop *desktop) : _desktop(desktop), _document(NULL) { - _layer_connection = desktop->connectCurrentLayerChanged(sigc::hide<0>(sigc::mem_fun(*this, &LayerManager::_rebuild))); - _document_connection = desktop->connectDocumentReplaced(sigc::hide<0>(sigc::mem_fun(*this, &LayerManager::_setDocument))); + sigc::slot base = sigc::mem_fun(*this, &LayerManager::_rebuild); + sigc::slot slot = sigc::hide<0>(base); + _layer_connection = desktop->connectCurrentLayerChanged(slot); + + sigc::bound_mem_functor1 first = sigc::mem_fun(*this, &LayerManager::_setDocument); + + // This next line has problems on gcc 4.0.2 + sigc::slot base2 = first; + + sigc::slot slot2 = sigc::hide<0>( base2 ); + _document_connection = desktop->connectDocumentReplaced( slot2 ); + _setDocument(desktop->doc()); } @@ -40,19 +50,26 @@ void LayerManager::_setDocument(SPDocument *document) { void LayerManager::_rebuild() { _clear(); - GSList const *layers=sp_document_get_resource_list(_document, "layers"); + GSList const *layers=sp_document_get_resource_list(_document, "layer"); + SPObject *root=_desktop->currentRoot(); + if ( root ) { + _addOne(root); + } for ( GSList const *iter=layers ; iter ; iter = iter->next ) { SPObject *layer=static_cast(iter->data); - _addOne(layer); - } - SPObject *root=_desktop->currentRoot(); - SPObject *layer=_desktop->currentLayer(); - for ( ; layer ; layer = SP_OBJECT_PARENT(layer) ) { - if (!includes(layer)) { - _addOne(layer); - } - if ( layer == root ) { - break; + + for ( SPObject* curr = layer; curr && (curr != root) ; curr = SP_OBJECT_PARENT(curr) ) { + if ( (curr != root) && root->isAncestorOf(curr) && !includes(curr) ) { + // Filter out objects in the middle of being deleted + SPObject const *higher = curr; + while ( higher && (SP_OBJECT_PARENT(higher) != root) ) { + higher = SP_OBJECT_PARENT(higher); + } + Inkscape::XML::Node* node = higher ? SP_OBJECT_REPR(higher) : 0; + if ( node && node->parent() ) { + _addOne(curr); + } + } } } } diff --git a/src/layer-manager.h b/src/layer-manager.h index 622cda1f2..48ef73c73 100644 --- a/src/layer-manager.h +++ b/src/layer-manager.h @@ -14,7 +14,7 @@ #include "gc-finalized.h" #include "gc-soft-ptr.h" -class SPDocument; +class SPDesktop; class SPDocument; namespace Inkscape { @@ -26,6 +26,7 @@ public: LayerManager(SPDesktop *desktop); private: + void _setDocument(SPDocument *document); void _rebuild();