From 6a8d99ab00ace2084820547572dc05ac8ad2bc5a 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 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. Change-Id: I4f72aa10103de29ce53fe3dd88457d093b705599 Task-number: QTBUG-46720 Reviewed-by: Jocelyn Turcotte (Woboq GmbH) --- src/webenginewidgets/api/qtwebenginewidgetsglobal.cpp | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/src/webenginewidgets/api/qtwebenginewidgetsglobal.cpp b/src/webenginewidgets/api/qtwebenginewidgetsglobal.cpp index 4feacf748..b17516ad6 100644 --- a/src/webenginewidgets/api/qtwebenginewidgetsglobal.cpp +++ b/src/webenginewidgets/api/qtwebenginewidgetsglobal.cpp @@ -38,13 +38,23 @@ #include "qtwebengineglobal.h" #include +#include QT_BEGIN_NAMESPACE static void initialize() { - QtWebEngine::initialize(); + //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; + } +#endif + qAddPreRoutine(QtWebEngine::initialize); } -Q_COREAPP_STARTUP_FUNCTION(initialize) +Q_CONSTRUCTOR_FUNCTION(initialize) QT_END_NAMESPACE -- cgit v1.2.3