Skip to content

Commit

Permalink
Defer opencl initialization after user has opted-in in settings
Browse files Browse the repository at this point in the history
Prevents a crash from #20363, actually deferring the crash
after the user has opted-in, btw the options is not stored
unless the user close the dialog, so a QGIS restart would
restore the status prior to the crash.

I've not been able to reproduce the crash on my windows
machines so I could not really get to the bottom of it,
this is just a workaround that should prevent the immediate
crash when opening the settings dialog.
  • Loading branch information
elpaso committed Dec 13, 2018
1 parent 1bc9234 commit 527448d
Show file tree
Hide file tree
Showing 2 changed files with 111 additions and 49 deletions.
60 changes: 38 additions & 22 deletions src/app/qgsoptions.cpp
Expand Up @@ -1086,32 +1086,48 @@ QgsOptions::QgsOptions( QWidget *parent, Qt::WindowFlags fl, const QList<QgsOpti

#ifdef HAVE_OPENCL

// Setup OpenCL (GPU) widget
mGPUEnableCheckBox->setChecked( QgsOpenClUtils::enabled( ) );
if ( QgsOpenClUtils::available( ) )
{
mGPUEnableCheckBox->setEnabled( true );
// Setup OpenCL Acceleration widget

for ( const auto &dev : QgsOpenClUtils::devices( ) )
connect( mGPUEnableCheckBox, &QCheckBox::toggled, [ = ]( bool checked )
{
if ( checked )
{
mOpenClDevicesCombo->addItem( QgsOpenClUtils::deviceInfo( QgsOpenClUtils::Info::Name, dev ), QgsOpenClUtils::deviceId( dev ) );
if ( QgsOpenClUtils::available( ) )
{
mOpenClContainerWidget->setEnabled( true );
mOpenClDevicesCombo->clear();

for ( const auto &dev : QgsOpenClUtils::devices( ) )
{
mOpenClDevicesCombo->addItem( QgsOpenClUtils::deviceInfo( QgsOpenClUtils::Info::Name, dev ), QgsOpenClUtils::deviceId( dev ) );
}
// Info updater
std::function<void( int )> infoUpdater = [ = ]( int )
{
mGPUInfoTextBrowser->setText( QgsOpenClUtils::deviceDescription( mOpenClDevicesCombo->currentData().toString() ) );
};
connect( mOpenClDevicesCombo, qgis::overload< int >::of( &QComboBox::currentIndexChanged ), infoUpdater );
mOpenClDevicesCombo->setCurrentIndex( mOpenClDevicesCombo->findData( QgsOpenClUtils::deviceId( QgsOpenClUtils::activeDevice() ) ) );
infoUpdater( -1 );
mOpenClContainerWidget->show();
}
else
{
mGPUInfoTextBrowser->setText( tr( "No OpenCL compatible devices were found on your system.<br>"
"You may need to install additional libraries in order to enable OpenCL.<br>"
"Please check your logs for further details." ) );
mOpenClContainerWidget->setEnabled( false );
mGPUEnableCheckBox->setChecked( false );
}
}
// Info updater
std::function<void( int )> infoUpdater = [ = ]( int )
else
{
mGPUInfoTextBrowser->setText( QgsOpenClUtils::deviceDescription( mOpenClDevicesCombo->currentData().toString() ) );
};
connect( mOpenClDevicesCombo, qgis::overload< int >::of( &QComboBox::currentIndexChanged ), infoUpdater );
mOpenClDevicesCombo->setCurrentIndex( mOpenClDevicesCombo->findData( QgsOpenClUtils::deviceId( QgsOpenClUtils::activeDevice() ) ) );
infoUpdater( -1 );
}
else
{
mGPUEnableCheckBox->setEnabled( false );
mGPUInfoTextBrowser->setText( tr( "An OpenCL compatible device was not found on your system.<br>"
"You may need to install additional libraries in order to enable OpenCL.<br>"
"Please check your logs for further details." ) );
}
mOpenClContainerWidget->setEnabled( false );
}
} );

mOpenClContainerWidget->setEnabled( false );
mGPUEnableCheckBox->setChecked( QgsOpenClUtils::enabled( ) );


#else
Expand Down
100 changes: 73 additions & 27 deletions src/ui/qgsoptionsbase.ui
Expand Up @@ -332,7 +332,7 @@
<item>
<widget class="QStackedWidget" name="mOptionsStackedWidget">
<property name="currentIndex">
<number>0</number>
<number>16</number>
</property>
<widget class="QWidget" name="mOptionsPageGeneral">
<layout class="QVBoxLayout" name="verticalLayout_3">
Expand Down Expand Up @@ -1083,7 +1083,7 @@
<x>0</x>
<y>0</y>
<width>544</width>
<height>1096</height>
<height>1095</height>
</rect>
</property>
<layout class="QVBoxLayout" name="verticalLayout_22">
Expand Down Expand Up @@ -3216,7 +3216,7 @@
<x>0</x>
<y>0</y>
<width>613</width>
<height>646</height>
<height>641</height>
</rect>
</property>
<layout class="QVBoxLayout" name="verticalLayout_30">
Expand Down Expand Up @@ -3659,7 +3659,7 @@ The bigger the number, the faster zooming with the mouse wheel will be.</string>
<rect>
<x>0</x>
<y>0</y>
<width>154</width>
<width>153</width>
<height>271</height>
</rect>
</property>
Expand Down Expand Up @@ -4867,8 +4867,8 @@ The bigger the number, the faster zooming with the mouse wheel will be.</string>
<rect>
<x>0</x>
<y>0</y>
<width>857</width>
<height>828</height>
<width>616</width>
<height>736</height>
</rect>
</property>
<layout class="QVBoxLayout" name="verticalLayout_33">
Expand Down Expand Up @@ -5332,31 +5332,49 @@ The bigger the number, the faster zooming with the mouse wheel will be.</string>
</widget>
</item>
<item>
<widget class="QLabel" name="label_64">
<widget class="QCheckBox" name="mGPUEnableCheckBox">
<property name="text">
<string>The following OpenCL devices were found on this system (changing the default device requires QGIS to be restarted).</string>
<string>Enable OpenCL acceleration</string>
</property>
</widget>
</item>
<item>
<widget class="QComboBox" name="mOpenClDevicesCombo"/>
</item>
<item>
<widget class="QTextBrowser" name="mGPUInfoTextBrowser">
<property name="html">
<string>&lt;!DOCTYPE HTML PUBLIC &quot;-//W3C//DTD HTML 4.0//EN&quot; &quot;http://www.w3.org/TR/REC-html40/strict.dtd&quot;&gt;
<widget class="QWidget" name="mOpenClContainerWidget" native="true">
<layout class="QVBoxLayout" name="verticalLayout_32">
<property name="leftMargin">
<number>0</number>
</property>
<property name="topMargin">
<number>0</number>
</property>
<property name="rightMargin">
<number>0</number>
</property>
<property name="bottomMargin">
<number>0</number>
</property>
<item>
<widget class="QLabel" name="label_64">
<property name="text">
<string>The following OpenCL devices were found on this system (changing the default device requires QGIS to be restarted).</string>
</property>
</widget>
</item>
<item>
<widget class="QComboBox" name="mOpenClDevicesCombo"/>
</item>
<item>
<widget class="QTextBrowser" name="mGPUInfoTextBrowser">
<property name="html">
<string>&lt;!DOCTYPE HTML PUBLIC &quot;-//W3C//DTD HTML 4.0//EN&quot; &quot;http://www.w3.org/TR/REC-html40/strict.dtd&quot;&gt;
&lt;html&gt;&lt;head&gt;&lt;meta name=&quot;qrichtext&quot; content=&quot;1&quot; /&gt;&lt;style type=&quot;text/css&quot;&gt;
p, li { white-space: pre-wrap; }
&lt;/style&gt;&lt;/head&gt;&lt;body style=&quot; font-family:'Noto Sans'; font-size:9pt; font-weight:400; font-style:normal;&quot;&gt;
&lt;p style=&quot; margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;&quot;&gt;Placemark for OpenCL information results (mGPUInfoTextBrowser)&lt;/p&gt;&lt;/body&gt;&lt;/html&gt;</string>
</property>
</widget>
</item>
<item>
<widget class="QCheckBox" name="mGPUEnableCheckBox">
<property name="text">
<string>Enable OpenCL acceleration</string>
</property>
&lt;/style&gt;&lt;/head&gt;&lt;body style=&quot; font-family:'Noto Sans'; font-size:10pt; font-weight:400; font-style:normal;&quot;&gt;
&lt;p style=&quot;-qt-paragraph-type:empty; margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;&quot;&gt;&lt;br /&gt;&lt;/p&gt;&lt;/body&gt;&lt;/html&gt;</string>
</property>
</widget>
</item>
</layout>
</widget>
</item>
<item>
Expand Down Expand Up @@ -5743,12 +5761,40 @@ p, li { white-space: pre-wrap; }
<tabstop>mRemoveUrlPushButton</tabstop>
<tabstop>mExcludeUrlListWidget</tabstop>
<tabstop>mAdvancedSettingsEnableButton</tabstop>
<tabstop>mOpenClDevicesCombo</tabstop>
<tabstop>mGPUInfoTextBrowser</tabstop>
<tabstop>mGPUEnableCheckBox</tabstop>
</tabstops>
<resources>
<include location="../../images/images.qrc"/>
<include location="../../images/images.qrc"/>
<include location="../../images/images.qrc"/>
<include location="../../images/images.qrc"/>
<include location="../../images/images.qrc"/>
<include location="../../images/images.qrc"/>
<include location="../../images/images.qrc"/>
<include location="../../images/images.qrc"/>
<include location="../../images/images.qrc"/>
<include location="../../images/images.qrc"/>
<include location="../../images/images.qrc"/>
<include location="../../images/images.qrc"/>
<include location="../../images/images.qrc"/>
<include location="../../images/images.qrc"/>
<include location="../../images/images.qrc"/>
<include location="../../images/images.qrc"/>
<include location="../../images/images.qrc"/>
<include location="../../images/images.qrc"/>
<include location="../../images/images.qrc"/>
<include location="../../images/images.qrc"/>
<include location="../../images/images.qrc"/>
<include location="../../images/images.qrc"/>
<include location="../../images/images.qrc"/>
<include location="../../images/images.qrc"/>
<include location="../../images/images.qrc"/>
<include location="../../images/images.qrc"/>
<include location="../../images/images.qrc"/>
<include location="../../images/images.qrc"/>
<include location="../../images/images.qrc"/>
<include location="../../images/images.qrc"/>
<include location="../../images/images.qrc"/>
<include location="../../images/images.qrc"/>
</resources>
<connections>
<connection>
Expand Down

0 comments on commit 527448d

Please sign in to comment.