Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
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 committed Jun 12, 2009
1 parent 7523b25 commit 8f7af1c
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 3 deletions.
18 changes: 15 additions & 3 deletions src/plugins/labeling/pallabeling.cpp
Expand Up @@ -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);

Expand All @@ -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();
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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();
}
Expand Down
3 changes: 3 additions & 0 deletions src/plugins/labeling/pallabeling.h
Expand Up @@ -7,6 +7,7 @@ class QgsMapCanvas;
#include <QString>
#include <QFont>
#include <QColor>
#include <QList>

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

class MyLabel;

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

class PalLabeling
Expand Down

0 comments on commit 8f7af1c

Please sign in to comment.