Skip to content

Commit 5464b0c

Browse files
committed
Guard from crashes for all uses of measureLine/measurePolygon
1 parent 711252d commit 5464b0c

File tree

3 files changed

+52
-7
lines changed

3 files changed

+52
-7
lines changed

src/core/distancearea.cpp

Lines changed: 34 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -138,10 +138,20 @@ void DistanceArea::setGeometry( Geometry *geometry )
138138

139139
qreal DistanceArea::length() const
140140
{
141+
double length = std::numeric_limits<double>::quiet_NaN();
141142
if ( mRubberbandModel )
142-
return mDistanceArea.measureLine( mRubberbandModel->flatPointSequence( mCrs ) );
143+
{
144+
try
145+
{
146+
length = mDistanceArea.measureLine( mRubberbandModel->flatPointSequence( mCrs ) );
147+
}
148+
catch ( const QgsException & )
149+
{
150+
length = std::numeric_limits<double>::quiet_NaN();
151+
}
152+
}
143153

144-
return qQNaN();
154+
return length;
145155
}
146156

147157
bool DistanceArea::lengthValid() const
@@ -197,10 +207,20 @@ bool DistanceArea::perimeterValid() const
197207

198208
qreal DistanceArea::area() const
199209
{
210+
double area = std::numeric_limits<double>::quiet_NaN();
200211
if ( mRubberbandModel )
201-
return mDistanceArea.measurePolygon( mRubberbandModel->flatPointSequence( mCrs ) );
212+
{
213+
try
214+
{
215+
area = mDistanceArea.measurePolygon( mRubberbandModel->flatPointSequence( mCrs ) );
216+
}
217+
catch ( const QgsException & )
218+
{
219+
area = std::numeric_limits<double>::quiet_NaN();
220+
}
221+
}
202222

203-
return qQNaN();
223+
return area;
204224
}
205225

206226
bool DistanceArea::areaValid() const
@@ -242,7 +262,16 @@ qreal DistanceArea::segmentLength() const
242262
pointIt--;
243263
flatPoints << *pointIt;
244264

245-
return mDistanceArea.measureLine( flatPoints );
265+
double length = std::numeric_limits<double>::quiet_NaN();
266+
try
267+
{
268+
length = mDistanceArea.measureLine( flatPoints );
269+
}
270+
catch ( const QgsException & )
271+
{
272+
length = std::numeric_limits<double>::quiet_NaN();
273+
}
274+
return length;
246275
}
247276

248277
qreal DistanceArea::azimuth() const

src/core/navigation.cpp

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -273,7 +273,16 @@ void Navigation::updateDetails()
273273
const QgsPoint destinationPoint = destination();
274274
const bool handleZ = QgsWkbTypes::hasZ( mLocation.wkbType() )
275275
&& QgsWkbTypes::hasZ( destinationPoint.wkbType() );
276-
mDistance = mDa.measureLine( mLocation, destinationPoint );
276+
277+
try
278+
{
279+
mDistance = mDa.measureLine( mLocation, destinationPoint );
280+
}
281+
catch ( const QgsException & )
282+
{
283+
mDistance = 0.0;
284+
}
285+
277286
if ( handleZ )
278287
{
279288
mVerticalDistance = destinationPoint.z() - mLocation.z();

src/core/tracker.cpp

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -205,7 +205,14 @@ void Tracker::positionReceived()
205205
QgsDistanceArea distanceArea;
206206
distanceArea.setEllipsoid( QgsProject::instance()->ellipsoid() );
207207
distanceArea.setSourceCrs( QgsProject::instance()->crs(), QgsProject::instance()->transformContext() );
208-
mCurrentDistance = distanceArea.measureLine( flatPoints );
208+
try
209+
{
210+
mCurrentDistance = distanceArea.measureLine( flatPoints );
211+
}
212+
catch ( const QgsException & )
213+
{
214+
mCurrentDistance = 0.0;
215+
}
209216
}
210217

211218
if ( !qgsDoubleNear( mMinimumDistance, 0.0 ) )

0 commit comments

Comments
 (0)