Skip to content
Permalink
Browse files

Fix crash while tracing and a layer is removed (fixes #14130)

  • Loading branch information
wonder-sk committed Jan 19, 2016
1 parent f27ab9a commit 4b079ae418667fead66029b744e6df4fec7f3f96
Showing with 10 additions and 0 deletions.
  1. +9 −0 src/core/qgstracer.cpp
  2. +1 −0 src/core/qgstracer.h
@@ -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;
@@ -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();
@@ -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
@@ -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

0 comments on commit 4b079ae

Please sign in to comment.
You can’t perform that action at this time.