From: kiirala Date: Sat, 16 May 2009 22:40:13 +0000 (+0000) Subject: Fixed crashes in feImage when modifying source, one caused by previous fix X-Git-Url: https://git.tokkee.org/?a=commitdiff_plain;h=6218828bc703f5da9d2be425927ff28ba320f3d1;p=inkscape.git Fixed crashes in feImage when modifying source, one caused by previous fix --- diff --git a/src/display/nr-filter-image.cpp b/src/display/nr-filter-image.cpp index 625aadf80..9679e56e7 100644 --- a/src/display/nr-filter-image.cpp +++ b/src/display/nr-filter-image.cpp @@ -37,7 +37,6 @@ FilterPrimitive * FilterImage::create() { FilterImage::~FilterImage() { if (feImageHref) g_free(feImageHref); - if (image_pixbuf) g_free(image_pixbuf); } int FilterImage::render(FilterSlot &slot, FilterUnits const &units) { @@ -59,6 +58,7 @@ int FilterImage::render(FilterSlot &slot, FilterUnits const &units) { nr_object_unref((NRObject *) arena); return 0; } + pb = new NRPixBlock; free_pb_on_exit = true; diff --git a/src/filters/image.cpp b/src/filters/image.cpp index a23ffeee4..1c92b772a 100644 --- a/src/filters/image.cpp +++ b/src/filters/image.cpp @@ -119,7 +119,8 @@ static void sp_feImage_release(SPObject *object) { SPFeImage *feImage = SP_FEIMAGE(object); - feImage->_modified_connection.disconnect(); + feImage->_image_modified_connection.disconnect(); + feImage->_href_modified_connection.disconnect(); if (feImage->SVGElemRef) delete feImage->SVGElemRef; if (((SPObjectClass *) feImage_parent_class)->release) @@ -132,6 +133,21 @@ sp_feImage_elem_modified(SPObject* /*href*/, guint /*flags*/, SPObject* obj) obj->parent->requestModified(SP_OBJECT_MODIFIED_FLAG); } +static void +sp_feImage_href_modified(SPObject* old_elem, SPObject* new_elem, SPObject* obj) +{ + SPFeImage *feImage = SP_FEIMAGE(obj); + feImage->_image_modified_connection.disconnect(); + if (new_elem) { + feImage->SVGElem = SP_ITEM(new_elem); + feImage->_image_modified_connection = ((SPObject*) feImage->SVGElem)->connectModified(sigc::bind(sigc::ptr_fun(&sp_feImage_elem_modified), obj)); + } else { + feImage->SVGElem = 0; + } + + obj->parent->requestModified(SP_OBJECT_MODIFIED_FLAG); +} + /** * Sets a specific value in the SPFeImage. */ @@ -148,16 +164,20 @@ sp_feImage_set(SPObject *object, unsigned int key, gchar const *value) } feImage->href = (value) ? g_strdup (value) : NULL; if (!feImage->href) return; + delete feImage->SVGElemRef; + feImage->SVGElemRef = 0; + feImage->SVGElem = 0; + feImage->_image_modified_connection.disconnect(); + feImage->_href_modified_connection.disconnect(); try{ Inkscape::URI SVGElem_uri(feImage->href); - delete feImage->SVGElemRef; feImage->SVGElemRef = new Inkscape::URIReference(feImage->document); - feImage->from_element = true; feImage->SVGElemRef->attach(SVGElem_uri); + feImage->from_element = true; + feImage->_href_modified_connection = feImage->SVGElemRef->changedSignal().connect(sigc::bind(sigc::ptr_fun(&sp_feImage_href_modified), object)); if (SPObject *elemref = feImage->SVGElemRef->getObject()) { feImage->SVGElem = SP_ITEM(elemref); - - feImage->_modified_connection = ((SPObject*) feImage->SVGElem)->connectModified(sigc::bind(sigc::ptr_fun(&sp_feImage_elem_modified), object)); + feImage->_image_modified_connection = ((SPObject*) feImage->SVGElem)->connectModified(sigc::bind(sigc::ptr_fun(&sp_feImage_elem_modified), object)); object->requestModified(SP_OBJECT_MODIFIED_FLAG); break; } else { @@ -167,10 +187,11 @@ sp_feImage_set(SPObject *object, unsigned int key, gchar const *value) catch(const Inkscape::UnsupportedURIException & e) { feImage->from_element = false; - g_warning("caught Inkscape::UnsupportedURIException in sp_feImage_set"); + /* This occurs when using external image as the source */ + //g_warning("caught Inkscape::UnsupportedURIException in sp_feImage_set"); break; } - + break; case SP_ATTR_X: feImage->x.readOrUnset(value); diff --git a/src/filters/image.h b/src/filters/image.h index 8952aee6c..7207918e1 100644 --- a/src/filters/image.h +++ b/src/filters/image.h @@ -31,7 +31,8 @@ struct SPFeImage : public SPFilterPrimitive { bool from_element; SPItem* SVGElem; Inkscape::URIReference* SVGElemRef; - sigc::connection _modified_connection; + sigc::connection _image_modified_connection; + sigc::connection _href_modified_connection; }; struct SPFeImageClass {