Code

Fixed warning
[inkscape.git] / src / sp-object.cpp
index 83bb7282c44dd5b617192d5c7d3cdbf397365f93..85e8a4e9ab4ad8898967f1de925bd74da2dbcb97 100644 (file)
@@ -42,6 +42,8 @@
 #include "style.h"
 #include "sp-object-repr.h"
 #include "sp-root.h"
+#include "sp-style-elem.h"
+#include "sp-script.h"
 #include "streq.h"
 #include "strneq.h"
 #include "xml/repr.h"
@@ -505,6 +507,13 @@ SPObject::setLabel(gchar const *label) {
 void
 SPObject::requestOrphanCollection() {
     g_return_if_fail(document != NULL);
+
+    // do not remove style or script elements (Bug #276244)
+    if (SP_IS_STYLE_ELEM(this))
+        return;
+    if (SP_IS_SCRIPT(this))
+        return;
+
     document->queueForOrphanCollection(this);
 
     /** \todo
@@ -817,7 +826,8 @@ sp_object_invoke_build(SPObject *object, SPDocument *document, Inkscape::XML::No
 
     object->document = document;
     object->repr = repr;
-    Inkscape::GC::anchor(repr);
+    if (!cloned)
+        Inkscape::GC::anchor(repr);
     object->cloned = cloned;
 
     if (!SP_OBJECT_IS_CLONED(object)) {
@@ -885,6 +895,8 @@ void SPObject::releaseReferences() {
         this->_default_label = NULL;
 
         this->document->bindObjectToRepr(this->repr, NULL);
+
+        Inkscape::GC::release(this->repr);
     } else {
         g_assert(!this->id);
     }
@@ -893,8 +905,6 @@ void SPObject::releaseReferences() {
         this->style = sp_style_unref(this->style);
     }
 
-    Inkscape::GC::release(this->repr);
-
     this->document = NULL;
     this->repr = NULL;
 }
@@ -1294,8 +1304,20 @@ SPObject::updateDisplay(SPCtx *ctx, unsigned int flags)
         }
     }
 
-    if (((SPObjectClass *) G_OBJECT_GET_CLASS(this))->update)
-        ((SPObjectClass *) G_OBJECT_GET_CLASS(this))->update(this, ctx, flags);
+    try
+    {
+        if (((SPObjectClass *) G_OBJECT_GET_CLASS(this))->update)
+            ((SPObjectClass *) G_OBJECT_GET_CLASS(this))->update(this, ctx, flags);
+    }
+    catch(...)
+    {
+        /** \todo 
+        * in case of catching an exception we need to inform the user somehow that the document is corrupted
+        * maybe by implementing an document flag documentOk
+        * or by a modal error dialog
+        */
+        g_warning("SPObject::updateDisplay(SPCtx *ctx, unsigned int flags) : throw in ((SPObjectClass *) G_OBJECT_GET_CLASS(this))->update(this, ctx, flags);");
+    }
 
     update_in_progress --;
 }
@@ -1531,24 +1553,6 @@ SPObject::_requireSVGVersion(Inkscape::Version version) {
     }
 }
 
-/**
- * Return sodipodi version of first root ancestor or (0,0).
- */
-Inkscape::Version
-sp_object_get_sodipodi_version(SPObject *object)
-{
-    static Inkscape::Version const zero_version(0, 0);
-
-    while (object) {
-        if (SP_IS_ROOT(object)) {
-            return SP_ROOT(object)->version.sodipodi;
-        }
-        object = SP_OBJECT_PARENT(object);
-    }
-
-    return zero_version;
-}
-
 /**
  * Returns previous object in sibling list or NULL.
  */