Skip to content

Commit

Permalink
Application termination: fix crash caused by 5288aed when layers are …
Browse files Browse the repository at this point in the history
…still opened at exit
  • Loading branch information
rouault committed Oct 20, 2017
1 parent 6ce4b60 commit fc016ec
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 6 deletions.
2 changes: 0 additions & 2 deletions src/app/qgisapp.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1317,8 +1317,6 @@ QgisApp::~QgisApp()
// cancel request for FileOpen events
QgsApplication::setFileOpenEventReceiver( nullptr );

delete QgsProject::instance();

delete mPythonUtils;

delete mTray;
Expand Down
6 changes: 4 additions & 2 deletions src/core/qgsapplication.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -891,11 +891,13 @@ void QgsApplication::exitQgis()
//LeakSanitiser noise which hides real issues
QgsApplication::sendPostedEvents( nullptr, QEvent::DeferredDelete );

delete QgsProviderRegistry::instance();

//delete all registered functions from expression engine (see above comment)
QgsExpression::cleanRegisteredFunctions();

delete QgsProject::instance();

delete QgsProviderRegistry::instance();

// tear-down GDAL/OGR
OGRCleanupAll();
GDALDestroyDriverManager();
Expand Down
4 changes: 4 additions & 0 deletions src/core/qgsproject.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -373,6 +373,10 @@ QgsProject::~QgsProject()
delete mRelationManager;
delete mLayerTreeRegistryBridge;
delete mRootGroup;
if ( this == sProject )
{
sProject = nullptr;
}
}


Expand Down
14 changes: 12 additions & 2 deletions src/core/qgsproviderregistry.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -45,11 +45,19 @@ typedef QString protocolDrivers_t();
//typedef int dataCapabilities_t();
//typedef QgsDataItem * dataItem_t(QString);


static QMutex mutex;

This comment has been minimized.

Copy link
@elpaso

elpaso Oct 20, 2017

Contributor

just curious: why did you make this static? It does not need to be, correct?

This comment has been minimized.

Copy link
@rouault

rouault Oct 20, 2017

Author Contributor

It would have global visibility otherwise. Or perhaps I'm confusing with C visibility rules. Hum... Anyway this mutex should better be moved inside the function. Will do that instead. And there is will need to be static :-)

static QgsProviderRegistry *sInstance = nullptr;

QgsProviderRegistry *QgsProviderRegistry::instance( const QString &pluginPath )
{
static QgsProviderRegistry *sInstance( new QgsProviderRegistry( pluginPath ) );
if ( !sInstance )
{
QMutexLocker locker( &mutex );
if ( !sInstance )
{
sInstance = new QgsProviderRegistry( pluginPath );
}
}
return sInstance;
} // QgsProviderRegistry::instance

Expand Down Expand Up @@ -256,6 +264,8 @@ void QgsProviderRegistry::clean()
QgsProviderRegistry::~QgsProviderRegistry()
{
clean();
if ( sInstance == this )
sInstance = nullptr;
}


Expand Down

0 comments on commit fc016ec

Please sign in to comment.