Skip to content

Commit 2d63f24

Browse files
committedDec 11, 2018
Defer opencl initialization after user has opted-in in settings
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.
1 parent bec04c1 commit 2d63f24

File tree

2 files changed

+111
-49
lines changed

2 files changed

+111
-49
lines changed
 

‎src/app/qgsoptions.cpp

Lines changed: 38 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -1086,32 +1086,48 @@ QgsOptions::QgsOptions( QWidget *parent, Qt::WindowFlags fl, const QList<QgsOpti
10861086

10871087
#ifdef HAVE_OPENCL
10881088

1089-
// Setup OpenCL (GPU) widget
1090-
mGPUEnableCheckBox->setChecked( QgsOpenClUtils::enabled( ) );
1091-
if ( QgsOpenClUtils::available( ) )
1092-
{
1093-
mGPUEnableCheckBox->setEnabled( true );
1089+
// Setup OpenCL Acceleration widget
10941090

1095-
for ( const auto &dev : QgsOpenClUtils::devices( ) )
1091+
connect( mGPUEnableCheckBox, &QCheckBox::toggled, [ = ]( bool checked )
1092+
{
1093+
if ( checked )
10961094
{
1097-
mOpenClDevicesCombo->addItem( QgsOpenClUtils::deviceInfo( QgsOpenClUtils::Info::Name, dev ), QgsOpenClUtils::deviceId( dev ) );
1095+
if ( QgsOpenClUtils::available( ) )
1096+
{
1097+
mOpenClContainerWidget->setEnabled( true );
1098+
mOpenClDevicesCombo->clear();
1099+
1100+
for ( const auto &dev : QgsOpenClUtils::devices( ) )
1101+
{
1102+
mOpenClDevicesCombo->addItem( QgsOpenClUtils::deviceInfo( QgsOpenClUtils::Info::Name, dev ), QgsOpenClUtils::deviceId( dev ) );
1103+
}
1104+
// Info updater
1105+
std::function<void( int )> infoUpdater = [ = ]( int )
1106+
{
1107+
mGPUInfoTextBrowser->setText( QgsOpenClUtils::deviceDescription( mOpenClDevicesCombo->currentData().toString() ) );
1108+
};
1109+
connect( mOpenClDevicesCombo, qgis::overload< int >::of( &QComboBox::currentIndexChanged ), infoUpdater );
1110+
mOpenClDevicesCombo->setCurrentIndex( mOpenClDevicesCombo->findData( QgsOpenClUtils::deviceId( QgsOpenClUtils::activeDevice() ) ) );
1111+
infoUpdater( -1 );
1112+
mOpenClContainerWidget->show();
1113+
}
1114+
else
1115+
{
1116+
mGPUInfoTextBrowser->setText( tr( "No OpenCL compatible devices were found on your system.<br>"
1117+
"You may need to install additional libraries in order to enable OpenCL.<br>"
1118+
"Please check your logs for further details." ) );
1119+
mOpenClContainerWidget->setEnabled( false );
1120+
mGPUEnableCheckBox->setChecked( false );
1121+
}
10981122
}
1099-
// Info updater
1100-
std::function<void( int )> infoUpdater = [ = ]( int )
1123+
else
11011124
{
1102-
mGPUInfoTextBrowser->setText( QgsOpenClUtils::deviceDescription( mOpenClDevicesCombo->currentData().toString() ) );
1103-
};
1104-
connect( mOpenClDevicesCombo, qgis::overload< int >::of( &QComboBox::currentIndexChanged ), infoUpdater );
1105-
mOpenClDevicesCombo->setCurrentIndex( mOpenClDevicesCombo->findData( QgsOpenClUtils::deviceId( QgsOpenClUtils::activeDevice() ) ) );
1106-
infoUpdater( -1 );
1107-
}
1108-
else
1109-
{
1110-
mGPUEnableCheckBox->setEnabled( false );
1111-
mGPUInfoTextBrowser->setText( tr( "An OpenCL compatible device was not found on your system.<br>"
1112-
"You may need to install additional libraries in order to enable OpenCL.<br>"
1113-
"Please check your logs for further details." ) );
1114-
}
1125+
mOpenClContainerWidget->setEnabled( false );
1126+
}
1127+
} );
1128+
1129+
mOpenClContainerWidget->setEnabled( false );
1130+
mGPUEnableCheckBox->setChecked( QgsOpenClUtils::enabled( ) );
11151131

11161132

11171133
#else

‎src/ui/qgsoptionsbase.ui

Lines changed: 73 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -332,7 +332,7 @@
332332
<item>
333333
<widget class="QStackedWidget" name="mOptionsStackedWidget">
334334
<property name="currentIndex">
335-
<number>0</number>
335+
<number>16</number>
336336
</property>
337337
<widget class="QWidget" name="mOptionsPageGeneral">
338338
<layout class="QVBoxLayout" name="verticalLayout_3">
@@ -1083,7 +1083,7 @@
10831083
<x>0</x>
10841084
<y>0</y>
10851085
<width>544</width>
1086-
<height>1096</height>
1086+
<height>1095</height>
10871087
</rect>
10881088
</property>
10891089
<layout class="QVBoxLayout" name="verticalLayout_22">
@@ -3216,7 +3216,7 @@
32163216
<x>0</x>
32173217
<y>0</y>
32183218
<width>613</width>
3219-
<height>646</height>
3219+
<height>641</height>
32203220
</rect>
32213221
</property>
32223222
<layout class="QVBoxLayout" name="verticalLayout_30">
@@ -3659,7 +3659,7 @@ The bigger the number, the faster zooming with the mouse wheel will be.</string>
36593659
<rect>
36603660
<x>0</x>
36613661
<y>0</y>
3662-
<width>154</width>
3662+
<width>153</width>
36633663
<height>271</height>
36643664
</rect>
36653665
</property>
@@ -4867,8 +4867,8 @@ The bigger the number, the faster zooming with the mouse wheel will be.</string>
48674867
<rect>
48684868
<x>0</x>
48694869
<y>0</y>
4870-
<width>857</width>
4871-
<height>828</height>
4870+
<width>616</width>
4871+
<height>736</height>
48724872
</rect>
48734873
</property>
48744874
<layout class="QVBoxLayout" name="verticalLayout_33">
@@ -5332,31 +5332,49 @@ The bigger the number, the faster zooming with the mouse wheel will be.</string>
53325332
</widget>
53335333
</item>
53345334
<item>
5335-
<widget class="QLabel" name="label_64">
5335+
<widget class="QCheckBox" name="mGPUEnableCheckBox">
53365336
<property name="text">
5337-
<string>The following OpenCL devices were found on this system (changing the default device requires QGIS to be restarted).</string>
5337+
<string>Enable OpenCL acceleration</string>
53385338
</property>
53395339
</widget>
53405340
</item>
53415341
<item>
5342-
<widget class="QComboBox" name="mOpenClDevicesCombo"/>
5343-
</item>
5344-
<item>
5345-
<widget class="QTextBrowser" name="mGPUInfoTextBrowser">
5346-
<property name="html">
5347-
<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;
5342+
<widget class="QWidget" name="mOpenClContainerWidget" native="true">
5343+
<layout class="QVBoxLayout" name="verticalLayout_32">
5344+
<property name="leftMargin">
5345+
<number>0</number>
5346+
</property>
5347+
<property name="topMargin">
5348+
<number>0</number>
5349+
</property>
5350+
<property name="rightMargin">
5351+
<number>0</number>
5352+
</property>
5353+
<property name="bottomMargin">
5354+
<number>0</number>
5355+
</property>
5356+
<item>
5357+
<widget class="QLabel" name="label_64">
5358+
<property name="text">
5359+
<string>The following OpenCL devices were found on this system (changing the default device requires QGIS to be restarted).</string>
5360+
</property>
5361+
</widget>
5362+
</item>
5363+
<item>
5364+
<widget class="QComboBox" name="mOpenClDevicesCombo"/>
5365+
</item>
5366+
<item>
5367+
<widget class="QTextBrowser" name="mGPUInfoTextBrowser">
5368+
<property name="html">
5369+
<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;
53485370
&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;
53495371
p, li { white-space: pre-wrap; }
5350-
&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;
5351-
&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>
5352-
</property>
5353-
</widget>
5354-
</item>
5355-
<item>
5356-
<widget class="QCheckBox" name="mGPUEnableCheckBox">
5357-
<property name="text">
5358-
<string>Enable OpenCL acceleration</string>
5359-
</property>
5372+
&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;
5373+
&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>
5374+
</property>
5375+
</widget>
5376+
</item>
5377+
</layout>
53605378
</widget>
53615379
</item>
53625380
<item>
@@ -5743,12 +5761,40 @@ p, li { white-space: pre-wrap; }
57435761
<tabstop>mRemoveUrlPushButton</tabstop>
57445762
<tabstop>mExcludeUrlListWidget</tabstop>
57455763
<tabstop>mAdvancedSettingsEnableButton</tabstop>
5746-
<tabstop>mOpenClDevicesCombo</tabstop>
5747-
<tabstop>mGPUInfoTextBrowser</tabstop>
5748-
<tabstop>mGPUEnableCheckBox</tabstop>
57495764
</tabstops>
57505765
<resources>
57515766
<include location="../../images/images.qrc"/>
5767+
<include location="../../images/images.qrc"/>
5768+
<include location="../../images/images.qrc"/>
5769+
<include location="../../images/images.qrc"/>
5770+
<include location="../../images/images.qrc"/>
5771+
<include location="../../images/images.qrc"/>
5772+
<include location="../../images/images.qrc"/>
5773+
<include location="../../images/images.qrc"/>
5774+
<include location="../../images/images.qrc"/>
5775+
<include location="../../images/images.qrc"/>
5776+
<include location="../../images/images.qrc"/>
5777+
<include location="../../images/images.qrc"/>
5778+
<include location="../../images/images.qrc"/>
5779+
<include location="../../images/images.qrc"/>
5780+
<include location="../../images/images.qrc"/>
5781+
<include location="../../images/images.qrc"/>
5782+
<include location="../../images/images.qrc"/>
5783+
<include location="../../images/images.qrc"/>
5784+
<include location="../../images/images.qrc"/>
5785+
<include location="../../images/images.qrc"/>
5786+
<include location="../../images/images.qrc"/>
5787+
<include location="../../images/images.qrc"/>
5788+
<include location="../../images/images.qrc"/>
5789+
<include location="../../images/images.qrc"/>
5790+
<include location="../../images/images.qrc"/>
5791+
<include location="../../images/images.qrc"/>
5792+
<include location="../../images/images.qrc"/>
5793+
<include location="../../images/images.qrc"/>
5794+
<include location="../../images/images.qrc"/>
5795+
<include location="../../images/images.qrc"/>
5796+
<include location="../../images/images.qrc"/>
5797+
<include location="../../images/images.qrc"/>
57525798
</resources>
57535799
<connections>
57545800
<connection>

0 commit comments

Comments
 (0)
Please sign in to comment.