Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Layer CRS validation is NOT thread safe, and can cause crashes
when a layer with unknown CRS is loaded in a background thread

We can't queue the connection to prompt for CRS (or warn via
messagebar), because the slot uses a modifiable reference which
may be deleted before the queued slot is called.

We also can't do ANY gui related stuff when this occurs. Best
we can do is log a warning and move on...
  • Loading branch information
nyalldawson committed Mar 14, 2019
1 parent 239f1dc commit fb6b3a7
Showing 1 changed file with 12 additions and 1 deletion.
13 changes: 12 additions & 1 deletion src/app/qgisapp.cpp
Expand Up @@ -527,7 +527,18 @@ static QgsMessageOutput *messageOutputViewer_()

static void customSrsValidation_( QgsCoordinateReferenceSystem &srs )
{
QgisApp::instance()->emitCustomCrsValidation( srs );
if ( QThread::currentThread() != QApplication::instance()->thread() )
{
// Running in a background thread -- we can't queue this connection, because
// srs is a reference and may be deleted before the queued slot is called.
// We also can't do ANY gui related stuff here. Best we can do is log
// a warning and move on...
QgsMessageLog::logMessage( QObject::tr( "Layer has unknown CRS" ) );
}
else
{
QgisApp::instance()->emitCustomCrsValidation( srs );
}
}

void QgisApp::emitCustomCrsValidation( QgsCoordinateReferenceSystem &srs )
Expand Down

0 comments on commit fb6b3a7

Please sign in to comment.