Code

remove SPDesktop from SPNamedView when it is destroyed. Fixing bug 183621, but anothe...
authorjohanengelen <johanengelen@users.sourceforge.net>
Thu, 17 Jan 2008 20:50:00 +0000 (20:50 +0000)
committerjohanengelen <johanengelen@users.sourceforge.net>
Thu, 17 Jan 2008 20:50:00 +0000 (20:50 +0000)
src/desktop.cpp
src/sp-namedview.cpp

index e52d2b50c2a7c1f95e2c669e8a53456a36d3111b..9498d539910940307901fb5ac8177430850cdf5f 100644 (file)
@@ -314,6 +314,8 @@ SPDesktop::init (SPNamedView *nv, SPCanvas *aCanvas)
 
 void SPDesktop::destroy()
 {
+    namedview->hide(this);
+
     _activate_connection.disconnect();
     _deactivate_connection.disconnect();
     _sel_modified_connection.disconnect();
@@ -1086,9 +1088,11 @@ SPDesktop::shutdown()
 
 bool SPDesktop::onDeleteUI (GdkEventAny*)
 {
-       if(shutdown()) return true;
-       destroyWidget();
-       return false;
+    if(shutdown()) 
+        return true;
+
+    destroyWidget();
+    return false;
 }
 
 /**
index 481f201cdf97bfbec737cd158114f33767348388..d26f0052963b437e1ecf13f9ff8d3091babad214 100644 (file)
@@ -281,9 +281,9 @@ static void sp_namedview_release(SPObject *object)
 
     // delete grids:
     while ( namedview->grids ) {
-        Inkscape::CanvasGrid *gr = (Inkscape::CanvasGrid *)namedview->grids->data;
+        Inkscape::CanvasGrid *gr = (Inkscape::CanvasGrid *)namedview->grids->data; // get first entry
         delete gr;
-        namedview->grids = g_slist_remove_link(namedview->grids, namedview->grids);
+        namedview->grids = g_slist_remove_link(namedview->grids, namedview->grids); // deletes first entry
     }
 
     if (((SPObjectClass *) parent_class)->release) {
@@ -575,6 +575,10 @@ sp_namedview_add_grid(SPNamedView *nv, Inkscape::XML::Node *repr, SPDesktop *des
             doc = sp_desktop_document(desktop);
         else
             doc = sp_desktop_document(static_cast<SPDesktop*>(nv->views->data));
+        if (!doc) {
+            g_warning("sp_namedview_add_grid - how come doc is null here?!");
+            return NULL;
+        }
         grid = Inkscape::CanvasGrid::NewGrid(nv, repr, doc, gridtype);
         nv->grids = g_slist_append(nv->grids, grid);
         //Initialize the snapping parameters for the new grid
@@ -833,13 +837,6 @@ void SPNamedView::hide(SPDesktop const *desktop)
     }
 
     views = g_slist_remove(views, desktop);
-
-    // delete grids:
-    while ( grids ) {
-        Inkscape::CanvasGrid *gr = (Inkscape::CanvasGrid *)grids->data;
-        delete gr;
-        grids = g_slist_remove_link(grids, grids);
-    }
 }
 
 void SPNamedView::activateGuides(gpointer desktop, gboolean active)