Details
-
Bug
-
Resolution: Won't Do
-
P1: Critical
-
None
-
6.6, 6.7, 6.8
-
None
Description
Trying to access the device pixel ratio in any way under wasm ultimately ends up in QWasmScreen::devicePixelRatio, which then queries the JS object property window.devicePixelRatio. If this occurs off the main thread however, it crashes since the window object doesn't exist outside the main thread.
I haven't tested this at all, but it seems to me it would be quite straightforward to fix as follows:
$ git diff diff --git a/src/plugins/platforms/wasm/qwasmscreen.cpp b/src/plugins/platforms/wasm/qwasmscreen.cpp index bed98b5c61..0376338dab 100644 --- a/src/plugins/platforms/wasm/qwasmscreen.cpp +++ b/src/plugins/platforms/wasm/qwasmscreen.cpp @@ -16,6 +16,7 @@ #include <QtCore/qcoreapplication.h> #include <QtGui/qguiapplication.h> #include <private/qhighdpiscaling_p.h> +#include <QtCore/private/qstdweb_p.h> #include <tuple> @@ -187,11 +188,13 @@ qreal QWasmScreen::devicePixelRatio() const // // The effective devicePixelRatio is the product of these two scale factors, upper-bounded // by window.devicePixelRatio in order to avoid e.g. allocating a 10x widget backing store. - double dpr = emscripten::val::global("window")["devicePixelRatio"].as<double>(); - emscripten::val visualViewport = emscripten::val::global("window")["visualViewport"]; - double scale = visualViewport.isUndefined() ? 1.0 : visualViewport["scale"].as<double>(); - double effectiveDevicePixelRatio = std::min(dpr * scale, dpr); - return qreal(effectiveDevicePixelRatio); + return qstdweb::runTaskOnMainThread<qreal>([]() { + double dpr = emscripten::val::global("window")["devicePixelRatio"].as<double>(); + emscripten::val visualViewport = emscripten::val::global("window")["visualViewport"]; + double scale = visualViewport.isUndefined() ? 1.0 : visualViewport["scale"].as<double>(); + double effectiveDevicePixelRatio = std::min(dpr * scale, dpr); + return qreal(effectiveDevicePixelRatio); + }); } QString QWasmScreen::name() const