koffice/krita/image

Cyrille Berger cyb at lepi.org
Sun Apr 26 17:22:43 CEST 2009


SVN commit 959575 by berger:

Fix: random crash when manipulating a grid

This patch also add a few assert/tests when nodes are deleted/created to ensure the perspective grid is always in a consistant state
This patch is looking for a reviewer for oking a backport.

CCMAIL:kimageshop at kde.org
BUG:189941

 M  +22 -0     kis_perspective_grid.cpp  
 M  +2 -0      kis_perspective_grid.h  


--- trunk/koffice/krita/image/kis_perspective_grid.cpp #959574:959575
@@ -33,13 +33,19 @@
 KisPerspectiveGridNode::KisPerspectiveGridNode(QPointF p) : QPointF(p), d(new Private)
 {
 }
+
+KisPerspectiveGridNode::KisPerspectiveGridNode(const KisPerspectiveGridNode& rhs) : QPointF(rhs), d(new Private()) {
+}
+
 KisPerspectiveGridNode::~KisPerspectiveGridNode()
 {
+    Q_ASSERT(d->subGrids.empty());
     delete d;
 }
 
 void KisPerspectiveGridNode::registerSubPerspectiveGrid(KisSubPerspectiveGrid* grid)
 {
+    Q_ASSERT(!d->subGrids.contains(grid));
     d->subGrids.append(grid);
 }
 
@@ -48,6 +54,10 @@
     d->subGrids.removeAll(grid);
 }
 
+bool KisPerspectiveGridNode::containsSubPerspectiveGrid(KisSubPerspectiveGrid* grid)
+{
+    return d->subGrids.contains(grid);
+}
 
 void KisPerspectiveGridNode::mergeWith(KisPerspectiveGridNodeSP node)
 {
@@ -87,6 +97,10 @@
     setTopRight(topRight);
     setBottomLeft(bottomLeft);
     setBottomRight(bottomRight);
+    Q_ASSERT(d->topLeft == topLeft);
+    Q_ASSERT(d->topRight == topRight);
+    Q_ASSERT(d->bottomLeft == bottomLeft);
+    Q_ASSERT(d->bottomRight == bottomRight);
     d->subdivisions = 5;
     d->index = ++Private::s_lastIndex;
 }
@@ -164,6 +178,8 @@
 
 void KisSubPerspectiveGrid::setTopLeft(KisPerspectiveGridNodeSP node)
 {
+    if(node->containsSubPerspectiveGrid(this)) return;
+    if(d->topLeft) d->topLeft->unRegisterSubPerspectiveGrid(this);
     d->topLeft = node;
     d->topLeft->registerSubPerspectiveGrid(this);
 }
@@ -180,6 +196,8 @@
 
 void KisSubPerspectiveGrid::setTopRight(KisPerspectiveGridNodeSP node)
 {
+    if(node->containsSubPerspectiveGrid(this)) return;
+    if(d->topRight) d->topRight->unRegisterSubPerspectiveGrid(this);
     d->topRight = node;
     d->topRight->registerSubPerspectiveGrid(this);
 }
@@ -196,6 +214,8 @@
 
 void KisSubPerspectiveGrid::setBottomLeft(KisPerspectiveGridNodeSP node)
 {
+    if(node->containsSubPerspectiveGrid(this)) return;
+    if(d->bottomLeft) d->bottomLeft->unRegisterSubPerspectiveGrid(this);
     d->bottomLeft = node;
     d->bottomLeft->registerSubPerspectiveGrid(this);
 }
@@ -212,6 +232,8 @@
 
 void KisSubPerspectiveGrid::setBottomRight(KisPerspectiveGridNodeSP node)
 {
+    if(node->containsSubPerspectiveGrid(this)) return;
+    if(d->bottomRight) d->bottomRight->unRegisterSubPerspectiveGrid(this);
     d->bottomRight = node;
     d->bottomRight->registerSubPerspectiveGrid(this);
 }
--- trunk/koffice/krita/image/kis_perspective_grid.h #959574:959575
@@ -42,11 +42,13 @@
 public:
     KisPerspectiveGridNode(double x, double y);
     KisPerspectiveGridNode(QPointF p);
+    KisPerspectiveGridNode(const KisPerspectiveGridNode&);
     ~KisPerspectiveGridNode();
     void mergeWith(KisPerspectiveGridNodeSP);
 private:
     void registerSubPerspectiveGrid(KisSubPerspectiveGrid*);
     void unRegisterSubPerspectiveGrid(KisSubPerspectiveGrid*);
+    bool containsSubPerspectiveGrid(KisSubPerspectiveGrid*);
 private:
     struct Private;
     Private* const d;


More information about the kimageshop mailing list