Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Do not crash on exit due to dangling layer pointer (fixes #18732)
When using attribute dialog to edit attributes of multiple selected features,
the dialog may stay alive until QGIS exits (parented to QgisApp) and its internal
QgsActionMenu would try to reload actions when they get removed in ~QgisApp,
referring to a deleted map layer, so let's clean things up when the layer gets
deleted to avoid trouble later.
  • Loading branch information
wonder-sk committed Jun 21, 2018
1 parent 692f439 commit 8609a2f
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 0 deletions.
10 changes: 10 additions & 0 deletions src/gui/qgsactionmenu.cpp
Expand Up @@ -47,6 +47,7 @@ void QgsActionMenu::init()
connect( mLayer, &QgsVectorLayer::editingStarted, this, &QgsActionMenu::reloadActions );
connect( mLayer, &QgsVectorLayer::editingStopped, this, &QgsActionMenu::reloadActions );
connect( mLayer, &QgsVectorLayer::readOnlyChanged, this, &QgsActionMenu::reloadActions );
connect( mLayer, &QgsMapLayer::willBeDeleted, this, &QgsActionMenu::layerWillBeDeleted );

reloadActions();
}
Expand Down Expand Up @@ -167,6 +168,15 @@ void QgsActionMenu::reloadActions()
emit reinit();
}

void QgsActionMenu::layerWillBeDeleted()
{
// here we are just making sure that we are not going to have reloadActions() called again
// with a dangling pointer to a layer when actions get removed on QGIS exit
clear();
mLayer = nullptr;
disconnect( QgsGui::mapLayerActionRegistry(), &QgsMapLayerActionRegistry::changed, this, &QgsActionMenu::reloadActions );
}


QgsActionMenu::ActionData::ActionData( QgsMapLayerAction *action, QgsFeatureId featureId, QgsMapLayer *mapLayer )
: actionType( MapLayerAction )
Expand Down
1 change: 1 addition & 0 deletions src/gui/qgsactionmenu.h
Expand Up @@ -119,6 +119,7 @@ class GUI_EXPORT QgsActionMenu : public QMenu
private slots:
void triggerAction();
void reloadActions();
void layerWillBeDeleted();

private:
void init();
Expand Down

0 comments on commit 8609a2f

Please sign in to comment.