From a8564cc6fb40fe6a9c3f5f6f37392a628aa5b685 Mon Sep 17 00:00:00 2001 From: Corentin Jabot Date: Wed, 16 Dec 2015 10:18:30 +0100 Subject: Never call QtWebEngine::initialize from DllMain MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 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) (cherry picked from commit 6a8d99ab00ace2084820547572dc05ac8ad2bc5a) Change-Id: Id3b2c1e21e01808cef124f8ece6b247b1ba613cb Reviewed-by: Michael BrĂ¼ning --- src/core/api/qtwebenginecoreglobal.cpp | 5 +++++ 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(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 +#include 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(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 -- cgit v1.2.3