Code

Fixed crashes in feImage when modifying source, one caused by previous fix
authorkiirala <kiirala@users.sourceforge.net>
Sat, 16 May 2009 22:40:13 +0000 (22:40 +0000)
committerkiirala <kiirala@users.sourceforge.net>
Sat, 16 May 2009 22:40:13 +0000 (22:40 +0000)
src/display/nr-filter-image.cpp
src/filters/image.cpp
src/filters/image.h

index 625aadf803e28ac83726cfa5daf71f3a1f71a79a..9679e56e7d949f475eb53d0f03adf6109ca7d48d 100644 (file)
@@ -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;
 
index a23ffeee4eba9dbe5ffea29d0fbd313e16dc8907..1c92b772a43f6c56817065b951367b831c5c01d0 100644 (file)
@@ -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);
index 8952aee6c3e932099197f733964a76108d5e0d88..7207918e12923a93014c9881003edaab46cbdec8 100644 (file)
@@ -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 {