Skip to content

Commit 06af43d

Browse files
committed
Don't crash when deleting last vertex
Fix #12867 Backported to 2.8.3 Also preserves NULL rectangles in QgsRectangle::normalize()
1 parent cbeacb7 commit 06af43d

File tree

2 files changed

+30
-14
lines changed

2 files changed

+30
-14
lines changed

src/core/qgspointlocator.cpp

+27-14
Original file line numberDiff line numberDiff line change
@@ -632,11 +632,14 @@ bool QgsPointLocator::rebuildIndex( int maxFeaturesToIndex )
632632
QgsRectangle rect = *mExtent;
633633
if ( mTransform )
634634
{
635-
try {
635+
try
636+
{
636637
rect = mTransform->transformBoundingBox( rect, QgsCoordinateTransform::ReverseTransform );
637-
} catch (const QgsException& e) {
638+
}
639+
catch ( const QgsException& e )
640+
{
638641
// See http://hub.qgis.org/issues/12634
639-
QgsDebugMsg( QString("could not transform bounding box to map, skipping the snap filter (%1)").arg(e.what()) );
642+
QgsDebugMsg( QString( "could not transform bounding box to map, skipping the snap filter (%1)" ).arg( e.what() ) );
640643
}
641644
}
642645
request.setFilterRect( rect );
@@ -650,11 +653,14 @@ bool QgsPointLocator::rebuildIndex( int maxFeaturesToIndex )
650653

651654
if ( mTransform )
652655
{
653-
try {
656+
try
657+
{
654658
f.geometry()->transform( *mTransform );
655-
} catch (const QgsException& e) {
659+
}
660+
catch ( const QgsException& e )
661+
{
656662
// See http://hub.qgis.org/issues/12634
657-
QgsDebugMsg( QString("could not transform geometry to map, skipping the snap for it (%1)").arg(e.what()) );
663+
QgsDebugMsg( QString( "could not transform geometry to map, skipping the snap for it (%1)" ).arg( e.what() ) );
658664
continue;
659665
}
660666
}
@@ -700,8 +706,8 @@ void QgsPointLocator::destroyIndex()
700706

701707
mIsEmptyLayer = false;
702708

703-
foreach ( QgsGeometry* g, mGeoms )
704-
delete g;
709+
qDeleteAll( mGeoms );
710+
705711
mGeoms.clear();
706712
}
707713

@@ -722,18 +728,25 @@ void QgsPointLocator::onFeatureAdded( QgsFeatureId fid )
722728

723729
if ( mTransform )
724730
{
725-
try {
731+
try
732+
{
726733
f.geometry()->transform( *mTransform );
727-
} catch (const QgsException& e) {
734+
}
735+
catch ( const QgsException& e )
736+
{
728737
// See http://hub.qgis.org/issues/12634
729-
QgsDebugMsg( QString("could not transform geometry to map, skipping the snap for it (%1)").arg(e.what()) );
738+
QgsDebugMsg( QString( "could not transform geometry to map, skipping the snap for it (%1)" ).arg( e.what() ) );
730739
return;
731740
}
732741
}
733742

734-
SpatialIndex::Region r( rect2region( f.geometry()->boundingBox() ) );
735-
mRTree->insertData( 0, 0, r, f.id() );
736-
mGeoms[fid] = new QgsGeometry( *f.geometry() );
743+
QgsRectangle bbox = f.geometry()->boundingBox();
744+
if ( !bbox.isNull() )
745+
{
746+
SpatialIndex::Region r( rect2region( bbox ) );
747+
mRTree->insertData( 0, 0, r, f.id() );
748+
mGeoms[fid] = new QgsGeometry( *f.geometry() );
749+
}
737750
}
738751
}
739752

src/core/qgsrectangle.cpp

+3
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,9 @@ void QgsRectangle::set( double xmin_, double ymin_, double xmax_, double ymax_ )
7777

7878
void QgsRectangle::normalize()
7979
{
80+
if ( isNull() )
81+
return;
82+
8083
if ( xmin > xmax )
8184
{
8285
std::swap( xmin, xmax );

0 commit comments

Comments
 (0)