Skip to content
Permalink
Browse files

Fix crash on exit when project signal is emitted during project destr…

…uction
  • Loading branch information
nyalldawson committed Jan 12, 2019
1 parent f7745c9 commit b0de40d9abf84808a2381708787a27d9dce46af4
Showing with 17 additions and 1 deletion.
  1. +8 −1 src/core/qgsproject.cpp
  2. +2 −0 src/core/qgsproject.h
  3. +7 −0 tests/src/python/test_qgsproject.py
@@ -406,6 +406,8 @@ QgsProject::QgsProject( QObject *parent )

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

clear();
delete mBadLayerHandler;
delete mRelationManager;
@@ -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
@@ -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
@@ -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.
You can’t perform that action at this time.