Skip to content

Commit

Permalink
Layer CRS validation is NOT thread safe, and can cause crashes
Browse files Browse the repository at this point in the history
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 13, 2019
1 parent 48068c2 commit 4db84a0
Showing 1 changed file with 12 additions and 1 deletion.
13 changes: 12 additions & 1 deletion src/app/qgisapp.cpp
Original file line number Diff line number Diff line change
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 4db84a0

Please sign in to comment.