Code

Workaround for some segfaults: Store perspectives globally instead of in each desktop...
authorcilix42 <cilix42@users.sourceforge.net>
Mon, 6 Aug 2007 07:20:23 +0000 (07:20 +0000)
committercilix42 <cilix42@users.sourceforge.net>
Mon, 6 Aug 2007 07:20:23 +0000 (07:20 +0000)
src/box3d-context.cpp
src/box3d.cpp
src/desktop.cpp
src/desktop.h
src/inkscape.cpp
src/perspective3d.cpp
src/perspective3d.h

index 7490875934d780354a9fb959444d096584bf1f24..5f1029576a6420e68a545fb61aa691f424f3a47f 100644 (file)
@@ -90,7 +90,6 @@ static void sp_3dbox_context_class_init(SP3DBoxContextClass *klass)
     event_context_class->item_handler  = sp_3dbox_context_item_handler;
 }
 
-Box3D::Perspective3D * Box3D::Perspective3D::current_perspective = NULL;
 guint SP3DBoxContext::number_of_handles = 3;
 
 static void sp_3dbox_context_init(SP3DBoxContext *box3d_context)
index fbf7fb15d82c169cc1bf7eb59d0c8184eba67af7..455a7889c16192adb209f90ddc463e30845b671a 100644 (file)
@@ -112,11 +112,10 @@ sp_3dbox_build(SPObject *object, SPDocument *document, Inkscape::XML::Node *repr
                                                                 Box3D::VanishingPoint (0,0),
                                                                 Box3D::VanishingPoint (0,0));
         sp_3dbox_update_perspective (persp, repr->attribute ("inkscape:perspective"));
-        SPDesktop *desktop = inkscape_active_desktop();
-        Box3D::Perspective3D *comp = desktop->find_perspective (persp);
+        Box3D::Perspective3D *comp =  Box3D::Perspective3D::find_perspective (persp);
         if (comp == NULL) {
             // perspective doesn't exist yet
-            desktop->add_perspective (persp);
+            Box3D::Perspective3D::add_perspective (persp);
             persp->add_box (box);
         } else {
             // link the box to the existing perspective and delete the temporary one
index f58864955d01641cbc2c4bbf52c27592349caa09..e785aab6dcd7a4b0e48cf1bfbc3e6f03cf5961fa 100644 (file)
@@ -132,7 +132,6 @@ SPDesktop::SPDesktop() :
     window_state(0),
     interaction_disabled_counter( 0 ),
     waiting_cursor( false ),
-    perspectives (NULL),
     guides_active( false ),
     gr_item( 0 ),
     gr_point_type( 0 ),
@@ -310,21 +309,6 @@ SPDesktop::init (SPNamedView *nv, SPCanvas *aCanvas)
     layer_manager = new Inkscape::LayerManager( this );
 
     grids_visible = true;
-
-    /* Create initial perspective, append it to the list of existing perspectives
-       and make it the current perspective */
-    Box3D::Perspective3D *initial_persp = new Box3D::Perspective3D (
-                                          // VP in x-direction
-                                          Box3D::VanishingPoint( NR::Point(-50.0, 600.0),
-                                                                 NR::Point( -1.0,   0.0), Box3D::VP_FINITE),
-                                          // VP in y-direction
-                                          Box3D::VanishingPoint( NR::Point(500.0,1000.0),
-                                                                 NR::Point(  0.0,   1.0), Box3D::VP_INFINITE),
-                                          // VP in z-direction
-                                          Box3D::VanishingPoint( NR::Point(700.0, 600.0),
-                                                                 NR::Point(sqrt(3.0),1.0), Box3D::VP_FINITE));
-    this->add_perspective (initial_persp);
-    Box3D::Perspective3D::current_perspective = (Box3D::Perspective3D *) perspectives->data;
 }
 
 
@@ -368,11 +352,6 @@ void SPDesktop::destroy()
 
     g_list_free (zooms_past);
     g_list_free (zooms_future);
-
-    for (GSList *p = this->perspectives; p != NULL; p = p->next) {
-        delete ((Box3D::Perspective3D *) p->data);
-    }
-    g_slist_free (perspectives);
 }
 
 SPDesktop::~SPDesktop() {}
@@ -714,45 +693,6 @@ void SPDesktop::set_display_area(NR::Rect const &a, NR::Coord b, bool log)
     set_display_area(a.min()[NR::X], a.min()[NR::Y], a.max()[NR::X], a.max()[NR::Y], b, log);
 }
 
-/**
- * Add a perspective to the desktop if it doesn't exist yet
- */
-void
-SPDesktop::add_perspective (Box3D::Perspective3D * const persp)
-{
-    // check that the perspective is not yet linked to another desktop
-    if (persp->desktop != NULL) {
-        g_assert (persp->desktop == this);
-    }
-
-    // FIXME: Should we handle the case that the perspectives have equal VPs but are not identical?
-    //        If so, we need to take care of relinking the boxes, etc.
-    if (persp == NULL || g_slist_find (this->perspectives, persp)) return;
-    this->perspectives = g_slist_prepend (this->perspectives, persp);
-    persp->desktop = this;
-}
-
-void SPDesktop::remove_perspective (Box3D::Perspective3D * const persp)
-{
-    if (persp == NULL) return;
-    if (!g_slist_find (this->perspectives, persp)) {
-        g_warning ("Could not find perspective in current desktop. Not removed.\n");
-        return;
-    }
-    this->perspectives = g_slist_remove (this->perspectives, persp);
-}
-
-// find an existing perspective whose VPs are equal to those of persp
-Box3D::Perspective3D * SPDesktop::find_perspective (Box3D::Perspective3D * const persp)
-{
-    for (GSList *p = this->perspectives; p != NULL; p = p->next) {
-        if (*((Box3D::Perspective3D *) p->data) == *persp) {
-            return ((Box3D::Perspective3D *) p->data);
-        }
-    }
-    return NULL; // perspective was not found
-}
-
 /**
  * Return viewbox dimensions.
  */
index 5f4e2cfab63a110d31fd5518da44fb91dd5642d7..ca2d2420465f919ac7ab474cc5c637b96eb76adc 100644 (file)
@@ -34,7 +34,6 @@
 #include "libnr/nr-rect.h"
 #include "ui/view/view.h"
 #include "ui/view/edit-widget-interface.h"
-#include "perspective3d.h"
 
 class NRRect;
 class SPCSSAttr;
@@ -113,9 +112,6 @@ struct SPDesktop : public Inkscape::UI::View::View
     unsigned int interaction_disabled_counter;
     bool waiting_cursor;
 
-    // All 3D perspectives that are present in the current desktop
-    GSList *perspectives;
-
     /// \todo fixme: This has to be implemented in different way */
     guint guides_active : 1;
 
@@ -206,11 +202,6 @@ struct SPDesktop : public Inkscape::UI::View::View
     SPItem *group_at_point (NR::Point const p) const;
     NR::Point point() const;
 
-    // Methods to handle 3D perspective
-    void add_perspective (Box3D::Perspective3D * const persp);
-    void remove_perspective (Box3D::Perspective3D * const persp);
-    Box3D::Perspective3D * find_perspective (Box3D::Perspective3D * const persp); // find an existing perspective whose VPs are equal to those of persp
-
     NR::Rect get_display_area() const;
     void set_display_area (double x0, double y0, double x1, double y1, double border, bool log = true);
     void set_display_area(NR::Rect const &a, NR::Coord border, bool log = true);
index c167be493c0900a05a12b9560472da180c80b6a8..8f76edddfa92916cbf7fa0585d1329a56c450ed4 100644 (file)
@@ -59,6 +59,7 @@ using Inkscape::Extension::Internal::PrintWin32;
 #include "prefs-utils.h"
 #include "xml/repr.h"
 #include "io/sys.h"
+#include "perspective3d.h"
 
 #include "extension/init.h"
 
@@ -597,6 +598,21 @@ inkscape_application_init (const gchar *argv0, gboolean use_gui)
     /* Initialize the extensions */
     Inkscape::Extension::init();
 
+    /* Create an initial perspective, append it to the list of existing perspectives and make it current */
+    Box3D::Perspective3D *initial_persp = new Box3D::Perspective3D (
+                                          // VP in x-direction
+                                          Box3D::VanishingPoint( NR::Point(-50.0, 600.0),
+                                                                 NR::Point( -1.0,   0.0), Box3D::VP_FINITE),
+                                          // VP in y-direction
+                                          Box3D::VanishingPoint( NR::Point(500.0,1000.0),
+                                                                 NR::Point(  0.0,   1.0), Box3D::VP_INFINITE),
+                                          // VP in z-direction
+                                          Box3D::VanishingPoint( NR::Point(700.0, 600.0),
+                                                                 NR::Point(sqrt(3.0),1.0), Box3D::VP_FINITE));
+
+    Box3D::Perspective3D::current_perspective = initial_persp;
+    Box3D::Perspective3D::add_perspective (initial_persp);
+
     return;
 }
 
index 8188a1ed2f8335f16249b218e11f6aec7f12161d..dd05ec7c7cef6ca7563e75782a2a78ce25200908 100644 (file)
@@ -15,7 +15,7 @@
 #include "box3d-context.h"
 #include "perspective-line.h"
 #include <iostream>
-#include "desktop.h"
+#include "perspective3d.h"
 
 // can probably be removed later
 #include "inkscape.h"
 namespace Box3D {
 
 gint Perspective3D::counter = 0;
+GSList * Perspective3D::perspectives = NULL;
+Perspective3D * Perspective3D::current_perspective = NULL;
 
 Perspective3D *
 get_persp_of_box (const SP3DBox *box)
 {
-    SPDesktop *desktop = inkscape_active_desktop(); // Should we pass the desktop as an argument?
-    for (GSList *p = desktop->perspectives; p != NULL; p = p->next) {
+    for (GSList *p = Perspective3D::perspectives; p != NULL; p = p->next) {
         if (((Perspective3D *) p->data)->has_box (box))
             return (Perspective3D *) p->data;
     }
@@ -64,8 +65,7 @@ perspective_line_snap (NR::Point line_pt, Box3D::Axis dir, NR::Point ext_pt, Per
 }  
 
 Perspective3D::Perspective3D (VanishingPoint const &pt_x, VanishingPoint const &pt_y, VanishingPoint const &pt_z)
-    : desktop (NULL),
-      boxes (NULL)
+    : boxes (NULL)
 {
     vp_x = new VanishingPoint (pt_x);
     vp_y = new VanishingPoint (pt_y);
@@ -75,8 +75,7 @@ Perspective3D::Perspective3D (VanishingPoint const &pt_x, VanishingPoint const &
 }
 
 Perspective3D::Perspective3D (Perspective3D &other)
-    : desktop (other.desktop),
-      boxes (NULL) // FIXME: Should we add an option to copy the list of boxes?
+    : boxes (NULL) // Should we add an option to copy the list of boxes?
 {
     vp_x = new VanishingPoint (*other.vp_x);
     vp_y = new VanishingPoint (*other.vp_y);
@@ -85,13 +84,9 @@ Perspective3D::Perspective3D (Perspective3D &other)
     my_counter = Perspective3D::counter++;
 }
 
-
 Perspective3D::~Perspective3D ()
 {
-    // we can have desktop == NULL when building a box whose attribute "inkscape:perspective" is set
-    if (desktop != NULL) {
-        desktop->remove_perspective (this);
-    }
+    Perspective3D::remove_perspective (this);
 
     delete vp_x;
     delete vp_y;
@@ -254,15 +249,41 @@ Perspective3D::svg_string ()
 }
 ***/
 
+void
+Perspective3D::add_perspective (Box3D::Perspective3D * const persp)
+{
+    // FIXME: Should we handle the case that the perspectives have equal VPs but are not identical?
+    //        If so, we need to take care of relinking the boxes, etc.
+    if (persp == NULL || g_slist_find (Perspective3D::perspectives, persp)) return;
+    Perspective3D::perspectives = g_slist_prepend (Perspective3D::perspectives, persp);
+}
+
+void
+Perspective3D::remove_perspective (Box3D::Perspective3D * const persp)
+{
+    if (persp == NULL || !g_slist_find (Perspective3D::perspectives, persp)) return;
+    Perspective3D::perspectives = g_slist_remove (Perspective3D::perspectives, persp);
+}
+
+// find an existing perspective whose VPs are equal to those of persp
+Box3D::Perspective3D *
+Perspective3D::find_perspective (Box3D::Perspective3D * const persp)
+{
+    for (GSList *p = Perspective3D::perspectives; p != NULL; p = p->next) {
+        if (*((Box3D::Perspective3D *) p->data) == *persp) {
+            return ((Box3D::Perspective3D *) p->data);
+        }
+    }
+    return NULL; // perspective was not found
+}
+
 void
 Perspective3D::print_debugging_info ()
 {
     g_print ("====================================================\n");
-    SPDesktop *desktop = inkscape_active_desktop();
-    for (GSList *i = desktop->perspectives; i != NULL; i = i->next) {
+    for (GSList *i = Perspective3D::perspectives; i != NULL; i = i->next) {
         Perspective3D *persp = (Perspective3D *) i->data;
         g_print ("Perspective %d:\n", persp->my_counter);
-        //g_print ("Perspective:\n");
 
         VanishingPoint * vp = persp->get_vanishing_point(Box3D::X);
         g_print ("   VP X: (%f,%f) ", (*vp)[NR::X], (*vp)[NR::Y]);
index 4211c7b3b36dd07afc50b3820f555132d2df5ad1..43b0ca3d3776fb56c0ad7eeb603292a6d1d69671 100644 (file)
@@ -41,10 +41,13 @@ public:
     static gint counter; // for testing only
     gint my_counter; // for testing only
 
-    static void print_debugging_info();
-    static Perspective3D * current_perspective; // should current_perspective be moved to desktop.h?
+    static GSList * perspectives; // All existing 3D perspectives
+    static void add_perspective (Box3D::Perspective3D * const persp);
+    static void remove_perspective (Box3D::Perspective3D * const persp);
+    static Box3D::Perspective3D * find_perspective (Box3D::Perspective3D * const persp); // find an existing perspective whose VPs are equal to those of persp
 
-    SPDesktop * desktop; // we need to store the perspective's desktop to be able to access it in the destructor
+    static void print_debugging_info();
+    static Perspective3D * current_perspective;
 
 private:
     VanishingPoint *vp_x;