Skip to content

Commit

Permalink
Fix crash while tracing and a layer is removed (fixes #14130)
Browse files Browse the repository at this point in the history
  • Loading branch information
wonder-sk committed Jan 19, 2016
1 parent f27ab9a commit 4b079ae
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 0 deletions.
9 changes: 9 additions & 0 deletions src/core/qgstracer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -549,6 +549,7 @@ void QgsTracer::setLayers( const QList<QgsVectorLayer*>& layers )
disconnect( layer, SIGNAL( featureAdded( QgsFeatureId ) ), this, SLOT( onFeatureAdded( QgsFeatureId ) ) );
disconnect( layer, SIGNAL( featureDeleted( QgsFeatureId ) ), this, SLOT( onFeatureDeleted( QgsFeatureId ) ) );
disconnect( layer, SIGNAL( geometryChanged( QgsFeatureId, QgsGeometry& ) ), this, SLOT( onGeometryChanged( QgsFeatureId, QgsGeometry& ) ) );
disconnect( layer, SIGNAL( destroyed( QObject* ) ), this, SLOT( onLayerDestroyed( QObject* ) ) );
}

mLayers = layers;
Expand All @@ -558,6 +559,7 @@ void QgsTracer::setLayers( const QList<QgsVectorLayer*>& layers )
connect( layer, SIGNAL( featureAdded( QgsFeatureId ) ), this, SLOT( onFeatureAdded( QgsFeatureId ) ) );
connect( layer, SIGNAL( featureDeleted( QgsFeatureId ) ), this, SLOT( onFeatureDeleted( QgsFeatureId ) ) );
connect( layer, SIGNAL( geometryChanged( QgsFeatureId, QgsGeometry& ) ), this, SLOT( onGeometryChanged( QgsFeatureId, QgsGeometry& ) ) );
connect( layer, SIGNAL( destroyed( QObject* ) ), this, SLOT( onLayerDestroyed( QObject* ) ) );
}

invalidateGraph();
Expand Down Expand Up @@ -618,6 +620,13 @@ void QgsTracer::onGeometryChanged( QgsFeatureId fid, QgsGeometry& geom )
invalidateGraph();
}

void QgsTracer::onLayerDestroyed( QObject* obj )
{
// remove the layer before it is completely invalid (static_cast should be the safest cast)
mLayers.removeAll( static_cast<QgsVectorLayer*>( obj ) );
invalidateGraph();
}

QVector<QgsPoint> QgsTracer::findShortestPath( const QgsPoint& p1, const QgsPoint& p2, PathError* error )
{
init(); // does nothing if the graph exists already
Expand Down
1 change: 1 addition & 0 deletions src/core/qgstracer.h
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,7 @@ class CORE_EXPORT QgsTracer : public QObject
void onFeatureAdded( QgsFeatureId fid );
void onFeatureDeleted( QgsFeatureId fid );
void onGeometryChanged( QgsFeatureId fid, QgsGeometry& geom );
void onLayerDestroyed( QObject* obj );

private:
//! Graph data structure for path searching
Expand Down

0 comments on commit 4b079ae

Please sign in to comment.