From 772ae09b2141e798ef856fb06f1fa899eb404e2b Mon Sep 17 00:00:00 2001 From: cilix42 Date: Mon, 6 Aug 2007 07:20:23 +0000 Subject: [PATCH] Workaround for some segfaults: Store perspectives globally instead of in each desktop (this should probably be reverted later on) --- src/box3d-context.cpp | 1 - src/box3d.cpp | 5 ++-- src/desktop.cpp | 60 ------------------------------------------- src/desktop.h | 9 ------- src/inkscape.cpp | 16 ++++++++++++ src/perspective3d.cpp | 51 +++++++++++++++++++++++++----------- src/perspective3d.h | 9 ++++--- 7 files changed, 60 insertions(+), 91 deletions(-) diff --git a/src/box3d-context.cpp b/src/box3d-context.cpp index 749087593..5f1029576 100644 --- a/src/box3d-context.cpp +++ b/src/box3d-context.cpp @@ -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) diff --git a/src/box3d.cpp b/src/box3d.cpp index fbf7fb15d..455a7889c 100644 --- a/src/box3d.cpp +++ b/src/box3d.cpp @@ -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 diff --git a/src/desktop.cpp b/src/desktop.cpp index f58864955..e785aab6d 100644 --- a/src/desktop.cpp +++ b/src/desktop.cpp @@ -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. */ diff --git a/src/desktop.h b/src/desktop.h index 5f4e2cfab..ca2d24204 100644 --- a/src/desktop.h +++ b/src/desktop.h @@ -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); diff --git a/src/inkscape.cpp b/src/inkscape.cpp index c167be493..8f76edddf 100644 --- a/src/inkscape.cpp +++ b/src/inkscape.cpp @@ -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; } diff --git a/src/perspective3d.cpp b/src/perspective3d.cpp index 8188a1ed2..dd05ec7c7 100644 --- a/src/perspective3d.cpp +++ b/src/perspective3d.cpp @@ -15,7 +15,7 @@ #include "box3d-context.h" #include "perspective-line.h" #include -#include "desktop.h" +#include "perspective3d.h" // can probably be removed later #include "inkscape.h" @@ -24,12 +24,13 @@ 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]); diff --git a/src/perspective3d.h b/src/perspective3d.h index 4211c7b3b..43b0ca3d3 100644 --- a/src/perspective3d.h +++ b/src/perspective3d.h @@ -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; -- 2.30.2