Skip to content

Commit

Permalink
Don't crash when deleting last vertex
Browse files Browse the repository at this point in the history
Fix #12867

Backported to 2.8.3

Also preserves NULL rectangles in QgsRectangle::normalize()
  • Loading branch information
m-kuhn committed Jun 4, 2015
1 parent cbeacb7 commit 06af43d
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 14 deletions.
41 changes: 27 additions & 14 deletions src/core/qgspointlocator.cpp
Expand Up @@ -632,11 +632,14 @@ bool QgsPointLocator::rebuildIndex( int maxFeaturesToIndex )
QgsRectangle rect = *mExtent;
if ( mTransform )
{
try {
try
{
rect = mTransform->transformBoundingBox( rect, QgsCoordinateTransform::ReverseTransform );
} catch (const QgsException& e) {
}
catch ( const QgsException& e )
{
// See http://hub.qgis.org/issues/12634
QgsDebugMsg( QString("could not transform bounding box to map, skipping the snap filter (%1)").arg(e.what()) );
QgsDebugMsg( QString( "could not transform bounding box to map, skipping the snap filter (%1)" ).arg( e.what() ) );
}
}
request.setFilterRect( rect );
Expand All @@ -650,11 +653,14 @@ bool QgsPointLocator::rebuildIndex( int maxFeaturesToIndex )

if ( mTransform )
{
try {
try
{
f.geometry()->transform( *mTransform );
} catch (const QgsException& e) {
}
catch ( const QgsException& e )
{
// See http://hub.qgis.org/issues/12634
QgsDebugMsg( QString("could not transform geometry to map, skipping the snap for it (%1)").arg(e.what()) );
QgsDebugMsg( QString( "could not transform geometry to map, skipping the snap for it (%1)" ).arg( e.what() ) );
continue;
}
}
Expand Down Expand Up @@ -700,8 +706,8 @@ void QgsPointLocator::destroyIndex()

mIsEmptyLayer = false;

foreach ( QgsGeometry* g, mGeoms )
delete g;
qDeleteAll( mGeoms );

mGeoms.clear();
}

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

if ( mTransform )
{
try {
try
{
f.geometry()->transform( *mTransform );
} catch (const QgsException& e) {
}
catch ( const QgsException& e )
{
// See http://hub.qgis.org/issues/12634
QgsDebugMsg( QString("could not transform geometry to map, skipping the snap for it (%1)").arg(e.what()) );
QgsDebugMsg( QString( "could not transform geometry to map, skipping the snap for it (%1)" ).arg( e.what() ) );
return;
}
}

SpatialIndex::Region r( rect2region( f.geometry()->boundingBox() ) );
mRTree->insertData( 0, 0, r, f.id() );
mGeoms[fid] = new QgsGeometry( *f.geometry() );
QgsRectangle bbox = f.geometry()->boundingBox();
if ( !bbox.isNull() )
{
SpatialIndex::Region r( rect2region( bbox ) );
mRTree->insertData( 0, 0, r, f.id() );
mGeoms[fid] = new QgsGeometry( *f.geometry() );
}
}
}

Expand Down
3 changes: 3 additions & 0 deletions src/core/qgsrectangle.cpp
Expand Up @@ -77,6 +77,9 @@ void QgsRectangle::set( double xmin_, double ymin_, double xmax_, double ymax_ )

void QgsRectangle::normalize()
{
if ( isNull() )
return;

if ( xmin > xmax )
{
std::swap( xmin, xmax );
Expand Down

0 comments on commit 06af43d

Please sign in to comment.