Code

Fix Bug #675309 - crash when unlinking an orphaned clone
[inkscape.git] / src / conn-avoid-ref.cpp
index b2aa0ce6bc1e9877242de5f3697a7a90048c410f..fe25fa418f5ad29b1f9179ee1eda0fa5ab35af9c 100644 (file)
@@ -28,6 +28,7 @@
 #include "libavoid/router.h"
 #include "libavoid/connector.h"
 #include "libavoid/geomtypes.h"
+#include "libavoid/shape.h"
 #include "xml/node.h"
 #include "document.h"
 #include "desktop.h"
@@ -63,8 +64,8 @@ SPAvoidRef::~SPAvoidRef()
     const bool routerInstanceExists = (item->document->router != NULL);
 
     if (shapeRef && routerInstanceExists) {
-        Router *router = shapeRef->router();
-        router->removeShape(shapeRef);
+        // Deleting the shapeRef will remove it completely from 
+        // an existing Router instance.
         delete shapeRef;
     }
     shapeRef = NULL;
@@ -329,7 +330,8 @@ void SPAvoidRef::handleSettingChange(void)
     {
         g_assert(shapeRef);
 
-        router->removeShape(shapeRef);
+        // Deleting the shapeRef will remove it completely from 
+        // an existing Router instance.
         delete shapeRef;
         shapeRef = NULL;
     }
@@ -341,7 +343,7 @@ GSList *SPAvoidRef::getAttachedShapes(const unsigned int type)
     GSList *list = NULL;
 
     Avoid::IntList shapes;
-    GQuark shapeId = g_quark_from_string(item->id);
+    GQuark shapeId = g_quark_from_string(item->getId());
     item->document->router->attachedShapes(shapes, shapeId, type);
 
     Avoid::IntList::iterator finish = shapes.end();
@@ -365,7 +367,7 @@ GSList *SPAvoidRef::getAttachedConnectors(const unsigned int type)
     GSList *list = NULL;
 
     Avoid::IntList conns;
-    GQuark shapeId = g_quark_from_string(item->id);
+    GQuark shapeId = g_quark_from_string(item->getId());
     item->document->router->attachedConns(conns, shapeId, type);
 
     Avoid::IntList::iterator finish = conns.end();
@@ -388,8 +390,6 @@ Geom::Point SPAvoidRef::getConnectionPointPos(const int type, const int id)
     g_assert(item);
     Geom::Point pos;
     const Geom::Matrix& transform = sp_item_i2doc_affine(item);
-    // TODO investigate why this was asking for the active desktop:
-    SPDesktop *desktop = inkscape_active_desktop();
 
     if ( type == ConnPointDefault )
     {
@@ -446,6 +446,12 @@ static std::vector<Geom::Point> approxCurveWithPoints(SPCurve *curve)
     {
         Geom::Path::const_iterator cit = pit->begin();
         while (cit != pit->end())
+        {
+            if (cit == pit->begin())
+            {
+                poly_points.push_back(cit->initialPoint());
+            }
+
             if (dynamic_cast<Geom::CubicBezier const*>(&*cit))
             {
                 at += seg_size;
@@ -462,6 +468,7 @@ static std::vector<Geom::Point> approxCurveWithPoints(SPCurve *curve)
                 poly_points.push_back(cit->finalPoint());
                 ++cit;
             }
+        }
         ++pit;
     }
     return poly_points;
@@ -520,7 +527,7 @@ static Avoid::Polygon avoid_item_poly(SPItem const *item)
     prev_parallel_hull_edge.origin(hull_edge.origin()+hull_edge.versor().ccw()*spacing);
     prev_parallel_hull_edge.versor(hull_edge.versor());
     int hull_size = hull.boundary.size();
-    for (int i = 0; i <= hull_size; ++i)
+    for (int i = 0; i < hull_size; ++i)
     {
         hull_edge.setBy2Points(hull[i], hull[i+1]);
         Geom::Line parallel_hull_edge;