Skip to content
Permalink
Browse files

Fixed an occasional segfault coming from incorrect geometry deletion.

git-svn-id: http://svn.osgeo.org/qgis/branches/symbology-ng-branch@10915 c8812cc2-4d05-0410-92ff-de0c093fc19c
  • Loading branch information
wonder
wonder committed Jun 12, 2009
1 parent 7523b25 commit 8f7af1c9f9d183f08db60590ba3db6cc3fa7c72a
Showing with 18 additions and 3 deletions.
  1. +15 −3 src/plugins/labeling/pallabeling.cpp
  2. +3 −0 src/plugins/labeling/pallabeling.h
@@ -89,9 +89,11 @@ void LayerSettings::registerFeature(QgsFeature& f)
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 @@ void LayerSettings::registerFeature(QgsFeature& f)
PalLabeling::PalLabeling(QgsMapCanvas* mapCanvas)
: mMapCanvas(mapCanvas), mPal(NULL)
{

// find out engine defaults
Pal p;
mCandPoint = p.getPointP();
@@ -244,6 +247,7 @@ void PalLabeling::initPal()
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 @@ void PalLabeling::doLabeling(QPainter* painter)
{
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,14 +312,22 @@ void PalLabeling::doLabeling(QPainter* painter)
painter->drawText(0,0, ((MyLabel*)label->getGeometry())->text());
painter->restore();

delete label->getGeometry();
delete label;
}

std::cout << "LABELING draw: " << t.elapsed() << "ms" << std::endl;

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();
}
@@ -7,6 +7,7 @@ class QgsMapCanvas;
#include <QString>
#include <QFont>
#include <QColor>
#include <QList>

namespace pal
{
@@ -18,6 +19,7 @@ class QgsMapToPixel;
class QgsFeature;
#include "qgspoint.h"

class MyLabel;

class LayerSettings
{
@@ -57,6 +59,7 @@ class LayerSettings
int fontBaseline;
const QgsMapToPixel* xform;
QgsPoint ptZero;
QList<MyLabel*> geometries;
};

class PalLabeling

0 comments on commit 8f7af1c

Please sign in to comment.
You can’t perform that action at this time.