QgsOpenClUtils::activate(): try to catch low-level Windows SEH to avoid hard crashes when OpenCL initialization fails

Tries to workaround #59617
Totally untested on my side. Might not be a good idea
This commit is contained in:
Even Rouault 2024-11-27 20:33:12 +01:00 committed by Nyall Dawson
parent 81f0fc300b
commit 9b3ea776a2

View File

@ -33,6 +33,11 @@
#include <tchar.h>
#endif
#if defined(_MSC_VER)
#include <windows.h>
#include <excpt.h>
#endif
QLatin1String QgsOpenClUtils::SETTINGS_GLOBAL_ENABLED_KEY = QLatin1String( "OpenClEnabled" );
QLatin1String QgsOpenClUtils::SETTINGS_DEFAULT_DEVICE_KEY = QLatin1String( "OpenClDefaultDevice" );
QLatin1String QgsOpenClUtils::LOGMESSAGE_TAG = QLatin1String( "OpenCL" );
@ -343,6 +348,11 @@ bool QgsOpenClUtils::activate( const QString &preferredDeviceId )
sAvailable = true;
return false;
}
#if defined(_MSC_VER)
// Try to capture hard crashes such as https://github.com/qgis/QGIS/issues/59617
__try
{
#endif
try
{
std::vector<cl::Platform> platforms;
@ -455,6 +465,16 @@ bool QgsOpenClUtils::activate( const QString &preferredDeviceId )
LOGMESSAGE_TAG, Qgis::MessageLevel::Warning );
sAvailable = false;
}
#if defined(_MSC_VER)
}
__except ( EXCEPTION_EXECUTE_HANDLER )
{
QgsMessageLog::logMessage( QObject::tr( "Unexpected exception of code %1 occurred while searching for OpenCL device. Note that the application may become unreliable and may need to be restarted." ).arg( GetExceptionCode() ),
LOGMESSAGE_TAG, Qgis::MessageLevel::Warning );
sAvailable = false;
}
#endif
return sAvailable;
}