[QGIS Commit] r10915 - branches/symbology-ng-branch/src/plugins/labeling

svn_qgis at osgeo.org svn_qgis at osgeo.org
Fri Jun 12 16:43:24 EDT 2009


Author: wonder
Date: 2009-06-12 16:43:24 -0400 (Fri, 12 Jun 2009)
New Revision: 10915

Modified:
   branches/symbology-ng-branch/src/plugins/labeling/pallabeling.cpp
   branches/symbology-ng-branch/src/plugins/labeling/pallabeling.h
Log:
Fixed an occasional segfault coming from incorrect geometry deletion.


Modified: branches/symbology-ng-branch/src/plugins/labeling/pallabeling.cpp
===================================================================
--- branches/symbology-ng-branch/src/plugins/labeling/pallabeling.cpp	2009-06-12 19:29:47 UTC (rev 10914)
+++ branches/symbology-ng-branch/src/plugins/labeling/pallabeling.cpp	2009-06-12 20:43:24 UTC (rev 10915)
@@ -89,9 +89,11 @@
   double labelX, labelY; // will receive label size
   calculateLabelSize(labelText, labelX, labelY);
 
-  //std::cout << labelX << " " << labelY << std::endl;
   MyLabel* lbl = new MyLabel(f.id(), labelText, GEOSGeom_clone( f.geometry()->asGeos() ) );
 
+  // record the created geometry - it will be deleted at the end.
+  geometries.append(lbl);
+
   // register feature to the layer
   palLayer->registerFeature(lbl->strId(), lbl, labelX, labelY);
 
@@ -106,6 +108,7 @@
 PalLabeling::PalLabeling(QgsMapCanvas* mapCanvas)
   : mMapCanvas(mapCanvas), mPal(NULL)
 {
+
   // find out engine defaults
   Pal p;
   mCandPoint = p.getPointP();
@@ -244,6 +247,7 @@
     case Popmusic_Tabu_Chain: s = POPMUSIC_TABU_CHAIN; break;
   }
   mPal->setSearch(s);
+  //mPal->setSearch(FALP);
 
   // set number of candidates generated per feature
   mPal->setPointP(mCandPoint);
@@ -278,7 +282,7 @@
   {
      labels = mPal->labeller(scale, bbox, NULL, false);
   }
-  catch ( std::exception e )
+  catch ( std::exception& e )
   {
     std::cerr << "PAL EXCEPTION :-( " << e.what() << std::endl;
     return;
@@ -308,7 +312,6 @@
     painter->drawText(0,0, ((MyLabel*)label->getGeometry())->text());
     painter->restore();
 
-    delete label->getGeometry();
     delete label;
   }
 
@@ -316,6 +319,15 @@
 
   delete labels;
 
+  // delete all allocated geometries for features
+  for (int i = 0; i < mLayers.count(); i++)
+  {
+    LayerSettings& lyr = mLayers[i];
+    for (QList<MyLabel*>::iterator git = lyr.geometries.begin(); git != lyr.geometries.end(); ++git)
+      delete *git;
+    lyr.geometries.clear();
+  }
+
   // re-create PAL
   initPal();
 }

Modified: branches/symbology-ng-branch/src/plugins/labeling/pallabeling.h
===================================================================
--- branches/symbology-ng-branch/src/plugins/labeling/pallabeling.h	2009-06-12 19:29:47 UTC (rev 10914)
+++ branches/symbology-ng-branch/src/plugins/labeling/pallabeling.h	2009-06-12 20:43:24 UTC (rev 10915)
@@ -7,6 +7,7 @@
 #include <QString>
 #include <QFont>
 #include <QColor>
+#include <QList>
 
 namespace pal
 {
@@ -18,6 +19,7 @@
 class QgsFeature;
 #include "qgspoint.h"
 
+class MyLabel;
 
 class LayerSettings
 {
@@ -57,6 +59,7 @@
   int fontBaseline;
   const QgsMapToPixel* xform;
   QgsPoint ptZero;
+  QList<MyLabel*> geometries;
 };
 
 class PalLabeling



More information about the QGIS-commit mailing list