Skip to content
Permalink
Browse files

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 20, 2018
1 parent 692f439 commit 8609a2fa88dfb7e85919689ccc96abcf97c3aaac
Showing with 11 additions and 0 deletions.
  1. +10 −0 src/gui/qgsactionmenu.cpp
  2. +1 −0 src/gui/qgsactionmenu.h
@@ -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();
}
@@ -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 )
@@ -119,6 +119,7 @@ class GUI_EXPORT QgsActionMenu : public QMenu
private slots:
void triggerAction();
void reloadActions();
void layerWillBeDeleted();

private:
void init();

0 comments on commit 8609a2f

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