From 6e5d89bf9595648fcebcf76fd031ba1ea022d397 Mon Sep 17 00:00:00 2001 From: Jabier Arraiza Date: Fri, 9 Mar 2018 00:50:57 +0100 Subject: Fixing refs --- src/live_effects/effect.cpp | 4 ---- src/live_effects/lpe-measure-segments.cpp | 4 ---- src/live_effects/lpe-powermask.cpp | 2 -- src/live_effects/lpeobject-reference.cpp | 23 +++++++++++---------- src/object/sp-ellipse.cpp | 7 +------ src/object/sp-lpe-item.cpp | 33 +++++++++++-------------------- src/object/sp-object.cpp | 6 +++++- src/object/sp-object.h | 1 - src/object/sp-shape.cpp | 6 ++++-- src/object/sp-shape.h | 2 +- src/object/sp-tref.cpp | 2 -- src/object/sp-use.cpp | 2 -- src/ui/tool/path-manipulator.cpp | 12 ++++------- src/ui/tools/eraser-tool.cpp | 11 ----------- src/ui/tools/tweak-tool.cpp | 2 -- src/verbs.cpp | 2 -- 16 files changed, 40 insertions(+), 79 deletions(-) (limited to 'src') diff --git a/src/live_effects/effect.cpp b/src/live_effects/effect.cpp index bfc280ce6..80fa208fa 100644 --- a/src/live_effects/effect.cpp +++ b/src/live_effects/effect.cpp @@ -488,9 +488,7 @@ Effect::processObjects(LpeAction lpe_action) switch (lpe_action){ case LPE_TO_OBJECTS: if (item->isHidden()) { - sp_object_ref(item, 0 ); item->deleteObject(true); - sp_object_unref(item); } else { if (elemnode->attribute("inkscape:path-effect")) { sp_item_list_to_curves(item_list, item_selected, item_to_select); @@ -500,9 +498,7 @@ Effect::processObjects(LpeAction lpe_action) break; case LPE_ERASE: - sp_object_ref(item, 0 ); item->deleteObject(true); - sp_object_unref(item); break; case LPE_VISIBILITY: diff --git a/src/live_effects/lpe-measure-segments.cpp b/src/live_effects/lpe-measure-segments.cpp index cff5aec4b..151403c5c 100644 --- a/src/live_effects/lpe-measure-segments.cpp +++ b/src/live_effects/lpe-measure-segments.cpp @@ -339,9 +339,7 @@ LPEMeasureSegments::createTextLabel(Geom::Point pos, size_t counter, double leng Inkscape::XML::Node *copy = old_repr->duplicate(xml_doc); SPObject * elemref_copy = sp_lpe_item->parent->appendChildRepr(copy); Inkscape::GC::release(copy); - sp_object_ref(elemref, 0 ); elemref->deleteObject(true); - sp_object_unref(elemref); copy->setAttribute("id", id.c_str()); elemref = elemref_copy; } @@ -490,9 +488,7 @@ LPEMeasureSegments::createLine(Geom::Point start,Geom::Point end, Glib::ustring Inkscape::XML::Node *copy = old_repr->duplicate(xml_doc); SPObject * elemref_copy = sp_lpe_item->parent->appendChildRepr(copy); Inkscape::GC::release(copy); - sp_object_ref(elemref, 0 ); elemref->deleteObject(true); - sp_object_unref(elemref); copy->setAttribute("id", id.c_str()); } } diff --git a/src/live_effects/lpe-powermask.cpp b/src/live_effects/lpe-powermask.cpp index 202c97259..577d8a841 100644 --- a/src/live_effects/lpe-powermask.cpp +++ b/src/live_effects/lpe-powermask.cpp @@ -203,9 +203,7 @@ LPEPowerMask::setMask(){ mask->getRepr()->appendChild(mask_node); Inkscape::GC::release(mask_node); } - sp_object_ref(elemref, 0 ); elemref->deleteObject(true); - sp_object_unref(elemref); } // } std::vector mask_list = mask->childList(true); diff --git a/src/live_effects/lpeobject-reference.cpp b/src/live_effects/lpeobject-reference.cpp index e96054212..1c04c909c 100644 --- a/src/live_effects/lpeobject-reference.cpp +++ b/src/live_effects/lpeobject-reference.cpp @@ -53,12 +53,14 @@ bool LPEObjectReference::_acceptObject(SPObject * const obj) const void LPEObjectReference::link(const char *to) { - if ( to == NULL ) { + if ( to && !to[0] ) { quit_listening(); unlink(); } else { if ( !lpeobject_href || ( strcmp(to, lpeobject_href) != 0 ) ) { - g_free(lpeobject_href); + if (lpeobject_href) { + g_free(lpeobject_href); + } lpeobject_href = g_strdup(to); try { attach(Inkscape::URI(to)); @@ -98,9 +100,6 @@ LPEObjectReference::start_listening(LivePathEffectObject* to) void LPEObjectReference::quit_listening(void) { - if ( lpeobject == NULL ) { - return; - } _modified_connection.disconnect(); _delete_connection.disconnect(); lpeobject_repr = NULL; @@ -122,16 +121,20 @@ lpeobjectreference_href_changed(SPObject */*old_ref*/, SPObject */*ref*/, LPEObj static void lpeobjectreference_delete_self(SPObject */*deleted*/, LPEObjectReference *lpeobjref) { - lpeobjref->quit_listening(); - lpeobjref->unlink(); - if (lpeobjref->user_unlink) - lpeobjref->user_unlink(lpeobjref, lpeobjref->owner); + lpeobjref->quit_listening(); + lpeobjref->unlink(); + if (lpeobjref->user_unlink) { + lpeobjref->user_unlink(lpeobjref, lpeobjref->owner); + } } static void lpeobjectreference_source_modified(SPObject */*iSource*/, guint /*flags*/, LPEObjectReference *lpeobjref) { - lpeobjref->owner->requestDisplayUpdate(SP_OBJECT_MODIFIED_FLAG); + SPObject *owner_obj = lpeobjref->owner; + if (owner_obj) { + lpeobjref->owner->requestDisplayUpdate(SP_OBJECT_MODIFIED_FLAG); + } } } //namespace LivePathEffect diff --git a/src/object/sp-ellipse.cpp b/src/object/sp-ellipse.cpp index 95bfd6160..6fc34bbb2 100644 --- a/src/object/sp-ellipse.cpp +++ b/src/object/sp-ellipse.cpp @@ -481,12 +481,7 @@ void SPGenericEllipse::set_shape() * This is very important for LPEs to work properly! (the bbox might be recalculated depending on the curve in shape)*/ SPCurve * before = this->getCurveBeforeLPE(); if (before || this->hasPathEffectRecursive()) { - if (!before || before->get_pathvector() != c->get_pathvector()){ - this->setCurveBeforeLPE(c); - this->update_patheffect(false); - } else { - this->setCurveBeforeLPE(c); - } + this->setCurveBeforeLPE(c); } else { this->setCurveInsync(c); } diff --git a/src/object/sp-lpe-item.cpp b/src/object/sp-lpe-item.cpp index e0ef848af..17b2710f8 100644 --- a/src/object/sp-lpe-item.cpp +++ b/src/object/sp-lpe-item.cpp @@ -87,15 +87,7 @@ void SPLPEItem::release() { delete this->lpe_modified_connection_list; this->lpe_modified_connection_list = NULL; - PathEffectList::iterator it = this->path_effect_list->begin(); - - while ( it != this->path_effect_list->end() ) { - // unlink and delete all references in the list - (*it)->unlink(); - delete *it; - it = this->path_effect_list->erase(it); - } - + this->path_effect_list->clear(); // delete the list itself delete this->path_effect_list; this->path_effect_list = NULL; @@ -128,7 +120,6 @@ void SPLPEItem::set(unsigned int key, gchar const* value) { delete *it; it = this->path_effect_list->erase(it); } - // Parse the contents of "value" to rebuild the path effect reference list if ( value ) { std::istringstream iss(value); @@ -527,9 +518,9 @@ void SPLPEItem::addPathEffect(LivePathEffectObject * new_lpeobj) void SPLPEItem::removeCurrentPathEffect(bool keep_paths) { Inkscape::LivePathEffect::LPEObjectReference* lperef = this->getCurrentLPEReference(); - if (!lperef) + if (!lperef) { return; - + } if (Inkscape::LivePathEffect::Effect* effect_ = this->getCurrentLPE()) { effect_->keep_paths = keep_paths; effect_->doOnRemove(this); @@ -556,11 +547,14 @@ void SPLPEItem::removeAllPathEffects(bool keep_paths) return; } } - - PathEffectList::iterator it = this->path_effect_list->begin(); - - while ( it != this->path_effect_list->end() ) { - LivePathEffectObject *lpeobj = (*it)->lpeobject; + PathEffectList new_list = *this->path_effect_list; + std::list::iterator i; + for (i = new_list.begin(); i != new_list.end(); ++i) { + Inkscape::LivePathEffect::LPEObjectReference *lperef = (*i); + if (!lperef) { + continue; + } + LivePathEffectObject *lpeobj = lperef->lpeobject; if (lpeobj) { Inkscape::LivePathEffect::Effect * lpe = lpeobj->get_lpe(); if (lpe) { @@ -568,11 +562,8 @@ void SPLPEItem::removeAllPathEffects(bool keep_paths) lpe->doOnRemove(this); } } - // unlink and delete all references in the list - (*it)->unlink(); - ++it; } - this->path_effect_list->clear(); + new_list.clear(); this->getRepr()->setAttribute("inkscape:path-effect", NULL); if (!keep_paths) { diff --git a/src/object/sp-object.cpp b/src/object/sp-object.cpp index d3c429c2a..112a08fb9 100644 --- a/src/object/sp-object.cpp +++ b/src/object/sp-object.cpp @@ -17,6 +17,7 @@ #include #include + #include #include "helper/sp-marshal.h" @@ -27,6 +28,7 @@ #include "document.h" #include "preferences.h" #include "style.h" +#include "live_effects/lpeobject.h" #include "sp-factory.h" #include "sp-paint-server.h" #include "sp-root.h" @@ -454,6 +456,8 @@ void SPObject::requestOrphanCollection() { // leave it } else if (IS_COLORPROFILE(this)) { // leave it + } else if (IS_LIVEPATHEFFECT(this)) { + document->queueForOrphanCollection(this); } else { document->queueForOrphanCollection(this); @@ -1198,7 +1202,7 @@ void SPObject::requestDisplayUpdate(unsigned int flags) bool already_propagated = (!(this->uflags & (SP_OBJECT_MODIFIED_FLAG | SP_OBJECT_CHILD_MODIFIED_FLAG))); this->uflags |= flags; - + /* If requestModified has already been called on this object or one of its children, then we * don't need to set CHILD_MODIFIED on our ancestors because it's already been done. */ diff --git a/src/object/sp-object.h b/src/object/sp-object.h index ee092aa7b..f969e0c0a 100644 --- a/src/object/sp-object.h +++ b/src/object/sp-object.h @@ -58,7 +58,6 @@ class SPObject; #include #include #include - #include "version.h" #include "util/forward-pointer-iterator.h" diff --git a/src/object/sp-shape.cpp b/src/object/sp-shape.cpp index 07416650e..48252a1d9 100644 --- a/src/object/sp-shape.cpp +++ b/src/object/sp-shape.cpp @@ -733,7 +733,7 @@ void SPShape::print(SPPrintContext* ctx) { if (add_comments) { gchar * comment = g_strdup_printf("end '%s'", - this->defaultLabel()); + this->defaultLabel()); sp_print_comment(ctx, comment); g_free(comment); } @@ -1033,7 +1033,7 @@ void SPShape::setCurve(SPCurve *new_curve, unsigned int owner) * Sets _curve_before_lpe to refer to the curve. */ void -SPShape::setCurveBeforeLPE(SPCurve *new_curve, unsigned int owner) +SPShape::setCurveBeforeLPE(SPCurve *new_curve, unsigned int owner, bool write) { if (_curve_before_lpe) { _curve_before_lpe = _curve_before_lpe->unref(); @@ -1046,6 +1046,8 @@ SPShape::setCurveBeforeLPE(SPCurve *new_curve, unsigned int owner) _curve_before_lpe = new_curve->copy(); } } + sp_lpe_item_update_patheffect(this, true, write); + requestDisplayUpdate(SP_OBJECT_MODIFIED_FLAG); } /** diff --git a/src/object/sp-shape.h b/src/object/sp-shape.h index be097e390..76d11d52c 100644 --- a/src/object/sp-shape.h +++ b/src/object/sp-shape.h @@ -43,7 +43,7 @@ public: SPCurve * getCurveBeforeLPE (unsigned int owner = FALSE) const; SPCurve * getCurveForEdit (unsigned int owner = FALSE) const; void setCurve (SPCurve *curve, unsigned int owner = TRUE); - void setCurveBeforeLPE (SPCurve *new_curve, unsigned int owner = TRUE); + void setCurveBeforeLPE (SPCurve *new_curve, unsigned int owner = TRUE, bool write = FALSE); void setCurveInsync (SPCurve *curve, unsigned int owner = TRUE); int hasMarkers () const; int numberOfMarkers (int type) const; diff --git a/src/object/sp-tref.cpp b/src/object/sp-tref.cpp index dd44c5855..eae852a89 100644 --- a/src/object/sp-tref.cpp +++ b/src/object/sp-tref.cpp @@ -482,7 +482,6 @@ sp_tref_convert_to_tspan(SPObject *obj) new_tspan->updateRepr(); // Hold onto our SPObject and repr for now. - sp_object_ref(tref, NULL); Inkscape::GC::anchor(tref_repr); // Remove ourselves, not propagating delete events to avoid a @@ -495,7 +494,6 @@ sp_tref_convert_to_tspan(SPObject *obj) // Establish the succession and let go of our object. tref->setSuccessor(new_tspan); - sp_object_unref(tref, NULL); } } //////////////////// diff --git a/src/object/sp-use.cpp b/src/object/sp-use.cpp index 2837e56f1..af61e392b 100644 --- a/src/object/sp-use.cpp +++ b/src/object/sp-use.cpp @@ -695,7 +695,6 @@ SPItem *SPUse::unlink() { unlinked->updateRepr(); // Hold onto our SPObject and repr for now. - sp_object_ref(this, NULL); Inkscape::GC::anchor(repr); // Remove ourselves, not propagating delete events to avoid a @@ -715,7 +714,6 @@ SPItem *SPUse::unlink() { // Establish the succession and let go of our object. this->setSuccessor(unlinked); - sp_object_unref(this, NULL); SPItem *item = dynamic_cast(unlinked); g_assert(item != NULL); diff --git a/src/ui/tool/path-manipulator.cpp b/src/ui/tool/path-manipulator.cpp index dcf0a4d4b..67d914095 100644 --- a/src/ui/tool/path-manipulator.cpp +++ b/src/ui/tool/path-manipulator.cpp @@ -190,8 +190,7 @@ void PathManipulator::writeXML() { if (!_live_outline) _updateOutline(); - if (_live_objects) - _setGeometry(); + _setGeometry(); if (!_path) return; _observer->block(); @@ -201,9 +200,7 @@ void PathManipulator::writeXML() } else { // this manipulator will have to be destroyed right after this call _getXMLNode()->removeObserver(*_observer); - sp_object_ref(_path); _path->deleteObject(true, true); - sp_object_unref(_path); _path = NULL; } _observer->unblock(); @@ -1393,8 +1390,7 @@ void PathManipulator::_createGeometryFromControlPoints(bool alert_LPE) } if (_live_outline) _updateOutline(); - if (_live_objects) - _setGeometry(); + _setGeometry(); } /** Build one segment of the geometric representation. @@ -1515,8 +1511,8 @@ void PathManipulator::_setGeometry() if (empty()) return; if (SPCurve * original = _path->getCurveBeforeLPE()){ if(!_spcurve->is_equal(original)) { - _path->setCurveBeforeLPE(_spcurve); - delete original; + _path->setCurveBeforeLPE(_spcurve, false, false); + original->unref(); } } else if(!_spcurve->is_equal(_path->getCurve(true))) { _path->setCurve(_spcurve, false); diff --git a/src/ui/tools/eraser-tool.cpp b/src/ui/tools/eraser-tool.cpp index 01ae71413..8bf4ad82d 100644 --- a/src/ui/tools/eraser-tool.cpp +++ b/src/ui/tools/eraser-tool.cpp @@ -702,10 +702,8 @@ void EraserTool::set_to_accumulated() { SPItem *item = *i; SPUse *use = dynamic_cast(item); if (SP_IS_PATH(item) && SP_PATH(item)->nodesInPath () == 2){ - sp_object_ref( *i, 0 ); SPItem *item = *i; item->deleteObject(true); - sp_object_unref(item); workDone = true; } else if (SP_IS_GROUP(item) || use ) { /*Do nothing*/ @@ -784,9 +782,7 @@ void EraserTool::set_to_accumulated() { SPItem * dup_clip_obj = SP_ITEM(item_repr->parent->appendChildRepr(dup_clip)); if (dup_clip_obj) { dup_clip_obj->doWriteTransform(item->transform); - sp_object_ref(clip_path, 0); clip_path->deleteObject(true); - sp_object_unref(clip_path); selection->raiseToTop(true); selection->add(dup_clip); selection->pathDiff(true); @@ -813,9 +809,7 @@ void EraserTool::set_to_accumulated() { } else { SPItem *erase_clip = selection->singleItem(); if (erase_clip) { - sp_object_ref(erase_clip, 0); erase_clip->deleteObject(true); - sp_object_unref(erase_clip); } } workDone = true; @@ -826,14 +820,9 @@ void EraserTool::set_to_accumulated() { } } } else { - for (std::vector ::const_iterator i = toWorkOn.begin();i!=toWorkOn.end();++i) { - sp_object_ref( *i, 0 ); - } - for (std::vector::const_iterator i = toWorkOn.begin();i!=toWorkOn.end();++i) { SPItem *item = *i; item->deleteObject(true); - sp_object_unref(item); workDone = true; } } diff --git a/src/ui/tools/tweak-tool.cpp b/src/ui/tools/tweak-tool.cpp index efa872ac1..6698316c7 100644 --- a/src/ui/tools/tweak-tool.cpp +++ b/src/ui/tools/tweak-tool.cpp @@ -468,9 +468,7 @@ sp_tweak_dilate_recursive (Inkscape::Selection *selection, SPItem *item, Geom::P double chance = g_random_double_range(0, 1); if (chance <= prob) { if (reverse) { // delete - sp_object_ref(item, NULL); item->deleteObject(true, true); - sp_object_unref(item, NULL); } else { // duplicate SPDocument *doc = item->document; Inkscape::XML::Document* xml_doc = doc->getReprDoc(); diff --git a/src/verbs.cpp b/src/verbs.cpp index 0e57063dc..2038e213f 100644 --- a/src/verbs.cpp +++ b/src/verbs.cpp @@ -1461,7 +1461,6 @@ void LayerVerb::perform(SPAction *action, void *data) dt->getSelection()->clear(); SPObject *old_layer=dt->currentLayer(); - sp_object_ref(old_layer, NULL); SPObject *survivor=Inkscape::next_layer(dt->currentRoot(), old_layer); if (!survivor) { survivor = Inkscape::previous_layer(dt->currentRoot(), old_layer); @@ -1477,7 +1476,6 @@ void LayerVerb::perform(SPAction *action, void *data) // http://sourceforge.net/tracker/index.php?func=detail&aid=1339397&group_id=93438&atid=604306 // old_layer->deleteObject(); - sp_object_unref(old_layer, NULL); if (survivor) { dt->setCurrentLayer(survivor); } -- cgit v1.2.3