Skip to content

Commit

Permalink
Fix crash on exit when project signal is emitted during project destr…
Browse files Browse the repository at this point in the history
…uction
  • Loading branch information
nyalldawson committed Jan 12, 2019
1 parent f7745c9 commit b0de40d
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 1 deletion.
9 changes: 8 additions & 1 deletion src/core/qgsproject.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -406,6 +406,8 @@ QgsProject::QgsProject( QObject *parent )

QgsProject::~QgsProject()
{
mIsBeingDeleted = true;

clear();
delete mBadLayerHandler;
delete mRelationManager;
Expand Down Expand Up @@ -714,7 +716,12 @@ void QgsProject::clear()
mArchive->clear();

emit labelingEngineSettingsChanged();
emit projectColorsChanged();

if ( !mIsBeingDeleted )
{
// possibly other signals should also not be thrown on destruction -- e.g. labelEngineSettingsChanged, etc.
emit projectColorsChanged();
}

// reset some default project properties
// XXX THESE SHOULD BE MOVED TO STATUSBAR RELATED SOURCE
Expand Down
2 changes: 2 additions & 0 deletions src/core/qgsproject.h
Original file line number Diff line number Diff line change
Expand Up @@ -1502,6 +1502,8 @@ class CORE_EXPORT QgsProject : public QObject, public QgsExpressionContextGenera

std::unique_ptr< QTranslator > mTranslator;

bool mIsBeingDeleted = false;

friend class QgsProjectDirtyBlocker;

// Required by QGIS Server for switching the current project instance
Expand Down
7 changes: 7 additions & 0 deletions tests/src/python/test_qgsproject.py
Original file line number Diff line number Diff line change
Expand Up @@ -1183,6 +1183,13 @@ def testColorScheme(self):
self.assertEqual(len(spy), 2)
self.assertEqual([[c[0].name(), c[1]] for c in scheme.fetchColors()], [])

# should be no signal on project destruction -- can cause a crash
p = QgsProject()
spy = QSignalSpy(p.projectColorsChanged)
p.deleteLater()
del p
self.assertEqual(len(spy), 0)


if __name__ == '__main__':
unittest.main()

0 comments on commit b0de40d

Please sign in to comment.