diff options
author | Corentin Jabot <corentinjabot@gmail.com> | 2015-12-16 10:18:30 +0100 |
---|---|---|
committer | Joerg Bornemann <joerg.bornemann@theqtcompany.com> | 2016-04-28 12:39:27 +0000 |
commit | a8564cc6fb40fe6a9c3f5f6f37392a628aa5b685 (patch) | |
tree | 351239294a30d992e4459818ec89e43e77cce625 | |
parent | f77cd97cacd1603fdca0c3fda405d351a1ccda93 (diff) |
Never call QtWebEngine::initialize from DllMain
On windows, calling QtWebEngine::initialize from DllMain may crash,
depending on what QPA backend is used.
We make sure to only add a qAddPreRoutine initializing QtWebEngine
if there is no instance of QCoreApplication.
By doing so, we support linking to QtWebEngineWidget from a plugin,
while still initializing the WebEngine automatically when linked to
the main application binary.
Task-number: QTBUG-46720
Reviewed-by: Jocelyn Turcotte (Woboq GmbH) <jturcotte@woboq.com>
(cherry picked from commit 6a8d99ab00ace2084820547572dc05ac8ad2bc5a)
Change-Id: Id3b2c1e21e01808cef124f8ece6b247b1ba613cb
Reviewed-by: Michael BrĂ¼ning <michael.bruning@theqtcompany.com>
-rw-r--r-- | src/core/api/qtwebenginecoreglobal.cpp | 5 | ||||
-rw-r--r-- | src/webenginewidgets/api/qtwebenginewidgetsglobal.cpp | 17 |
2 files changed, 16 insertions, 6 deletions
diff --git a/src/core/api/qtwebenginecoreglobal.cpp b/src/core/api/qtwebenginecoreglobal.cpp index 0e857d7d9..e60e6139e 100644 --- a/src/core/api/qtwebenginecoreglobal.cpp +++ b/src/core/api/qtwebenginecoreglobal.cpp @@ -75,6 +75,11 @@ QWEBENGINE_PRIVATE_EXPORT void initialize() qFatal("QtWebEngine::initialize() must be called after the construction of the application object."); return; } + + // Bail out silently if the user did not construct a QGuiApplication. + if (!qobject_cast<QGuiApplication *>(app)) + return; + if (app->thread() != QThread::currentThread()) { qFatal("QtWebEngine::initialize() must be called from the Qt gui thread."); return; diff --git a/src/webenginewidgets/api/qtwebenginewidgetsglobal.cpp b/src/webenginewidgets/api/qtwebenginewidgetsglobal.cpp index 263376e45..5ebb8b546 100644 --- a/src/webenginewidgets/api/qtwebenginewidgetsglobal.cpp +++ b/src/webenginewidgets/api/qtwebenginewidgetsglobal.cpp @@ -36,7 +36,7 @@ #include "qtwebenginewidgetsglobal.h" -#include <QGuiApplication> +#include <QCoreApplication> namespace QtWebEngineCore { @@ -46,13 +46,18 @@ namespace QtWebEngineCore QT_BEGIN_NAMESPACE static void initialize() { - // Bail out silently if the user did not construct a QGuiApplication. - if (!qobject_cast<QGuiApplication *>(QCoreApplication::instance())) + //On window/ANGLE, calling QtWebEngine::initialize from DllMain will result in a crash. + //To ensure it doesn't, we check that when loading the library + //QCoreApplication is not yet instantiated, ensuring the call will be deferred +#if defined(Q_OS_WIN) + if (QCoreApplication::instance() + && QOpenGLContext::openGLModuleType() == QOpenGLContext::LibGLES) { return; - - QtWebEngineCore::initialize(); + } +#endif + qAddPreRoutine(QtWebEngineCore::initialize); } -Q_COREAPP_STARTUP_FUNCTION(initialize) +Q_CONSTRUCTOR_FUNCTION(initialize) QT_END_NAMESPACE |