Skip to content

QT 6.10.2 support for WASM build#455

Open
KasparMetsa wants to merge 3 commits intoMUME:masterfrom
KasparMetsa:qt-6.10
Open

QT 6.10.2 support for WASM build#455
KasparMetsa wants to merge 3 commits intoMUME:masterfrom
KasparMetsa:qt-6.10

Conversation

@KasparMetsa
Copy link
Contributor

@KasparMetsa KasparMetsa commented Feb 12, 2026

  • Also fixed the no async error
  • Needs emscripten 4.0.7 for QT 6.10.2

Summary by Sourcery

Add WebAssembly (WASM) support for the Qt 6.10.2 map canvas by switching to QOpenGLWindow on WASM, improving WebGL context handling, and updating build and platform-specific integration.

New Features:

  • Introduce a WASM-specific MapCanvas implementation based on QOpenGLWindow embedded via createWindowContainer, with appropriate surface format configuration for WebGL 2.0.
  • Add dedicated WASM build helper scripts, including a qt-cmake-based build script and a simple local HTTP server with COOP/COEP headers for running the WASM build.

Bug Fixes:

  • Prevent crashes and undefined behavior on WASM by tracking WebGL context loss, avoiding rendering and async batch work when the context is invalid, and handling reinitialization safely.
  • Fix compatibility issues with Qt 6.10+ by adapting QMetaEnum::valueToKey usage and disabling problematic Clang CTAD warnings for newer Qt versions.
  • Avoid application aborts on WebGL-specific GL errors by logging and clearing errors instead of calling std::abort() in WASM builds.

Enhancements:

  • Abstract canvas sizing via a SizeSource helper so MapCanvasViewport can work with both QWidget and QWindow backends.
  • Adjust OpenGL initialization and rendering paths to account for device pixel ratio differences, disabled multisampling, and QOpenGLWindow-specific behavior on WASM.
  • Refine cursor, gesture, tooltip, and canvas enable/disable handling to account for QWidget-only APIs not available with QOpenGLWindow.
  • Add additional GL error clearing and logging around VAO creation and during initialization on WASM to improve diagnostics.
  • Update macOS deployment to work around a macdeployqt -libpath bug in Qt 6.8+ by conditionally omitting the flag.
  • Ensure macOS builds consistently select desktop OpenGL instead of GLES when using Qt6OpenGL on Apple platforms.

Build:

  • Update Emscripten link flags to tune assertions, enable Asyncify, and disable GL temp buffer pooling for the WASM target.
  • Define GLM_ENABLE_EXPERIMENTAL to support newer GLM extensions used in the project.
  • Make Clang's -Werror=ctad-maybe-unsupported conditional on Qt versions older than 6.10.0 to maintain compatibility with Qt 6.10+.

Deployment:

  • Adjust macOS bundle deployment invocation of macdeployqt to avoid the -libpath option for Qt 6.8+ due to a known bug while preserving the existing behavior for older Qt versions.

Summary by Sourcery

Add robust Qt 6.10.2 WebAssembly support for the OpenGL map canvas while preserving desktop behavior and updating build/tooling for newer Qt, GLM, and platform quirks.

New Features:

  • Introduce a WASM-specific MapCanvas based on QOpenGLWindow embedded via createWindowContainer with appropriate WebGL 2.0 surface configuration.
  • Add a SizeSource abstraction so MapCanvasViewport can operate with either QWidget or QWindow-backed canvases.
  • Enable pinch-to-zoom handling at the MapWindow level, forwarding gestures into MapCanvas.

Bug Fixes:

  • Track WebGL context validity on WASM to avoid rendering and async batch work after context loss and to guard GL initialization and resize/paint paths.
  • Avoid aborting on WebGL GL errors in WASM builds by logging and clearing errors instead.
  • Fix Qt 6.10+ meta-enum compatibility by adapting QMetaEnum::valueToKey usage to the new quint64 signature.

Enhancements:

  • Adjust OpenGL initialization, DPI handling, multisampling, and framebuffer usage to account for WebGL limitations and QOpenGLWindow behavior on WASM.
  • Refine cursor handling, context menus, tooltips, and canvas enable/disable logic to account for QWidget-only APIs when running under WASM.
  • Improve diagnostics and robustness around VAO creation and GL error handling, including explicit error clearing and debug logging.
  • Make async map batch generation conditional on platform, using deferred (synchronous) execution and context checks on WASM to avoid crashes.
  • Relax Clang CTAD warnings for Qt 6.10+ and enable GLM experimental extensions for newer GLM versions.
  • Ensure macOS Qt6OpenGL builds consistently use desktop OpenGL instead of GLES.

Build:

  • Tune Emscripten link flags for WASM (disabling assertions, enabling Asyncify) to match the new Qt 6.10.2 toolchain requirements.

Deployment:

  • Work around a Qt 6.8+ macdeployqt bug by conditionally omitting the -libpath flag while preserving the previous behavior on older Qt versions.

@sourcery-ai
Copy link

sourcery-ai bot commented Feb 12, 2026

Reviewer's Guide

Adds Qt 6.10.2-compatible WebAssembly support for the map canvas by introducing a QOpenGLWindow-based WASM backend, tracking WebGL context loss, adapting async mesh generation and gestures, and updating CMake/build/deployment and OpenGL error handling for Qt and platform quirks.

Sequence diagram for pinch-to-zoom handling via MapWindow and MapCanvas

sequenceDiagram
    actor User
    participant InputDevice
    participant MapWindow
    participant QGestureEvent
    participant QPinchGesture
    participant MapCanvas

    User->>InputDevice: Perform pinch gesture
    InputDevice->>MapWindow: QEvent_Gesture
    MapWindow->>MapWindow: event(event)
    MapWindow->>QGestureEvent: dynamic_cast
    QGestureEvent-->>MapWindow: gesture(Qt_PinchGesture)
    MapWindow->>QPinchGesture: dynamic_cast
    QPinchGesture-->>MapWindow: pinch

    alt ScaleFactorChanged
        MapWindow->>MapCanvas: setPinchZoom(pinchFactor)
        MapCanvas->>MapCanvas: update()
    end

    alt GestureFinished
        MapWindow->>MapCanvas: endPinchZoom()
        MapCanvas->>MapCanvas: zoomChanged()
        MapCanvas->>MapCanvas: update()
    end

    MapWindow-->>InputDevice: event_handled
Loading

Class diagram for updated MapCanvas, viewport abstraction, and MapWindow

classDiagram
    class MapCanvas {
        +static bool isWasmContextLost()
        +static void resetWasmContextState()
        +explicit MapCanvas(MapData &mapData, PrespammedPath &prespammedPath, Mmapper2Group &groupManager)
        +explicit MapCanvas(MapData &mapData, PrespammedPath &prespammedPath, Mmapper2Group &groupManager, QWidget *parent)
        +void initializeGL()
        +void paintGL()
        +void resizeGL(int width, int height)
        +void setPinchZoom(float pinchFactor)
        +void endPinchZoom()
        +QWidget* getContainerWidget()
        +void setContainerWidget(QWidget *widget)
        -static bool s_wasmInitialized
        -static atomic_bool s_wasmContextLost
        -QWidget* m_containerWidget
    }

    class MapCanvasViewport {
        -SizeSource m_sizeSource
        glm~mat4~ m_viewProj
        glm~vec2~ m_worldMouse
        int m_currentLayer
        +MapCanvasViewport(QWidget &sizeSource)
        +MapCanvasViewport(QWindow &sizeSource)
        +int width() const
        +int height() const
        +Viewport getViewport() const
        +float getTotalScaleFactor() const
    }

    class SizeSource {
        -QWidget* m_widget
        -QWindow* m_window
        +SizeSource(QWidget &widget)
        +SizeSource(QWindow &window)
        +int width() const
        +int height() const
        +QRect rect() const
    }

    class MapCanvasInputState {
        +ScaleFactor m_scaleFactor
        +void setZoom(float zoom)
        +float getRawZoom() const
    }

    class MapWindow {
        -std~unique_ptr~<MapCanvas> m_canvas
        +MapWindow(MapData &mapData, PrespammedPath &pp, Mmapper2Group &gm, QWidget *parent)
        +MapCanvas* getCanvas() const
        +void resizeEvent(QResizeEvent *event)
        +bool event(QEvent *event)
        +void hideSplashImage()
    }

    class QWidget
    class QWindow
    class QOpenGLWidget
    class QOpenGLWindow

    MapCanvas ..|> MapCanvasViewport
    MapCanvas ..|> MapCanvasInputState
    MapCanvas --|> QOpenGLWidget
    MapCanvas --|> QOpenGLWindow

    MapCanvasViewport *-- SizeSource

    MapWindow o--> MapCanvas
    MapWindow --|> QWidget

    SizeSource --> QWidget
    SizeSource --> QWindow

    MapCanvas --> QWidget : uses_as_container
    MapWindow --> QOpenGLWindow : embeds_via_createWindowContainer
Loading

Class diagram for updated OpenGL error handling and context tracking

classDiagram
    class MapCanvas {
        +static bool isWasmContextLost()
        +static void resetWasmContextState()
        -static bool s_wasmInitialized
        -static atomic_bool s_wasmContextLost
        +void initializeGL()
        +void resizeGL(int width, int height)
        +void paintGL()
        +void updateMapBatches()
    }

    class LegacyFunctions {
        +void checkError()
        +int clearErrors()
        +void configureFbo(int samples)
        +void glGenVertexArrays(GLsizei n, GLuint *arrays)
    }

    class VAO {
        -GLuint m_vao
        +void emplace(SharedFunctions &sharedFunctions)
    }

    class OpenGL {
        -bool m_rendererInitialized
        +void initializeRenderer(float devicePixelRatio)
        +LegacyFunctions& getFunctions()
        +LegacyFunctions& getSharedFunctions(Badge_MapCanvas)
    }

    class MapCanvasRoomDrawer {
        +FutureSharedMapBatchFinisher generateMapDataFinisher(mctp_MapCanvasTextures textures, GLFont &font, Map &map)
    }

    class FutureSharedMapBatchFinisher
    class SharedMapBatchFinisher
    class std_abort

    MapCanvas --> OpenGL : uses
    OpenGL --> LegacyFunctions : owns
    VAO --> LegacyFunctions : uses_for_VAO_creation

    MapCanvasRoomDrawer --> MapCanvas : calls_isWasmContextLost
    MapCanvasRoomDrawer --> FutureSharedMapBatchFinisher
    FutureSharedMapBatchFinisher --> SharedMapBatchFinisher

    LegacyFunctions ..> std_abort : used_on_desktop_errors
    LegacyFunctions ..> MapCanvas : clearErrors_used_from_initializeGL
Loading

File-Level Changes

Change Details Files
Introduce a WASM-specific MapCanvas backend using QOpenGLWindow and a size abstraction that works for both QWidget and QWindow.
  • MapCanvas now derives from QOpenGLWindow on EMSCRIPTEN and from QOpenGLWidget on desktop, with separate constructors and conditional use of widget-only APIs (cursor, tooltips, size hints, enable/disable).
  • MapWindow embeds the QOpenGLWindow-based canvas via QWidget::createWindowContainer on WASM and uses the widget directly on desktop.
  • Added SizeSource and updated MapCanvasViewport to read size/rect from either a QWidget or a QWindow, enabling shared viewport logic across backends.
src/display/mapcanvas.h
src/display/mapcanvas.cpp
src/display/MapCanvasData.h
src/display/mapwindow.cpp
Handle WebGL context limitations and loss on WASM to avoid crashes and undefined behavior.
  • Added static WASM context state tracking (initialized + atomic contextLost) in MapCanvas, with guards in initializeGL, resizeGL, paintGL, and async batch updates to stop rendering or work when the context is invalid.
  • Adjusted OpenGL initialization to use QOpenGLWindow’s devicePixelRatio on WASM, changed error dialogs to be parentless, and disabled multisampling in OpenGL::initializeRenderer for WebAssembly.
  • Changed actuallyPaintGL to render directly to the default framebuffer on WASM instead of using FBOs, and ensured glFinish uses the appropriate context accessor for each backend.
src/display/mapcanvas_gl.cpp
src/display/mapcanvas.h
src/display/mapcanvas.cpp
src/opengl/OpenGL.cpp
Make async mesh generation and GL error handling WASM-safe and more debuggable.
  • In MapCanvasRoomDrawer, async map batch generation uses std::launch::deferred on WASM and early-outs if the WebGL context has been marked lost, with additional checks before heavy mesh generation.
  • Legacy::Functions::checkError no longer aborts on WebGL builds; instead it logs a warning, and a new clearErrors helper drains pending errors, which is used after initialization and before VAO creation.
  • VAO creation now clears pre-existing GL errors and logs created VAO IDs on WASM to improve diagnostics.
src/display/MapCanvasRoomDrawer.cpp
src/opengl/legacy/Legacy.cpp
src/opengl/legacy/Legacy.h
src/opengl/legacy/VAO.cpp
src/display/mapcanvas_gl.cpp
Adapt input, gestures, tooltips, and canvas visibility to the split QWidget/QOpenGLWindow design.
  • Moved pinch-zoom gesture handling from MapCanvas to MapWindow; MapWindow now grabs the pinch gesture and forwards zoom information to MapCanvas via new setPinchZoom/endPinchZoom methods.
  • Guarded QWidget-only APIs (customContextMenuRequested, show/hide, setMouseTracking, setEnabled, QToolTip, cursor changes, size hints) with EMSCRIPTEN conditionals and provided fallbacks or no-ops for the QOpenGLWindow-based canvas.
  • Updated event handlers to dispatch through QOpenGLWindow::event on WASM and QOpenGLWidget::event on desktop, and adjusted context menu popup location to use MapWindow on WASM.
src/display/mapcanvas.h
src/display/mapcanvas.cpp
src/display/mapwindow.h
src/display/mapwindow.cpp
src/mainwindow/mainwindow.cpp
src/mainwindow/utils.cpp
Update build system and platform integration for Qt 6.10+ and platform quirks (WASM, macOS, Clang).
  • For Emscripten builds, disabled runtime ASSERTIONS, enabled ASYNCIFY, and required GLM_ENABLE_EXPERIMENTAL globally for newer GLM versions.
  • On macOS with Qt6OpenGL, forced desktop OpenGL instead of GLES and made macdeployqt’s -libpath usage conditional on Qt version (workaround for a Qt 6.8+ bug).
  • Made Clang’s -Werror=ctad-maybe-unsupported conditional on Qt versions older than 6.10.0 to avoid build failures with newer moc output, and updated QMetaEnum::valueToKey usage to handle the Qt 6.10 signature change.
CMakeLists.txt
src/CMakeLists.txt
src/clock/mumeclock.cpp

Tips and commands

Interacting with Sourcery

  • Trigger a new review: Comment @sourcery-ai review on the pull request.
  • Continue discussions: Reply directly to Sourcery's review comments.
  • Generate a GitHub issue from a review comment: Ask Sourcery to create an
    issue from a review comment by replying to it. You can also reply to a
    review comment with @sourcery-ai issue to create an issue from it.
  • Generate a pull request title: Write @sourcery-ai anywhere in the pull
    request title to generate a title at any time. You can also comment
    @sourcery-ai title on the pull request to (re-)generate the title at any time.
  • Generate a pull request summary: Write @sourcery-ai summary anywhere in
    the pull request body to generate a PR summary at any time exactly where you
    want it. You can also comment @sourcery-ai summary on the pull request to
    (re-)generate the summary at any time.
  • Generate reviewer's guide: Comment @sourcery-ai guide on the pull
    request to (re-)generate the reviewer's guide at any time.
  • Resolve all Sourcery comments: Comment @sourcery-ai resolve on the
    pull request to resolve all Sourcery comments. Useful if you've already
    addressed all the comments and don't want to see them anymore.
  • Dismiss all Sourcery reviews: Comment @sourcery-ai dismiss on the pull
    request to dismiss all existing Sourcery reviews. Especially useful if you
    want to start fresh with a new review - don't forget to comment
    @sourcery-ai review to trigger a new review!

Customizing Your Experience

Access your dashboard to:

  • Enable or disable review features such as the Sourcery-generated pull request
    summary, the reviewer's guide, and others.
  • Change the review language.
  • Add, remove or edit custom review instructions.
  • Adjust other review settings.

Getting Help

Copy link

@sourcery-ai sourcery-ai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hey - I've found 2 issues, and left some high level feedback:

  • The EMSCRIPTEN-specific global state for WebGL context tracking in mapcanvas_gl.cpp (g_wasmInitialized, g_wasmContextLost, g_wasmInitAttempts) would be easier to reason about and test if it lived in a dedicated struct/namespace or as MapCanvas static members instead of file-level globals.
  • There is a lot of duplicated logic between the QOpenGLWidget and QOpenGLWindow code paths (e.g. MakeCurrentRaii, width/height/rect wrappers, event forwarding); consider factoring out common behavior behind small helpers or templates to reduce the number of #ifdef EMSCRIPTEN branches.
  • The new scripts/build-wasm.sh hardcodes local paths for emsdk and Qt; making these configurable via environment variables or script arguments would avoid breakage for other environments and CI.
Prompt for AI Agents
Please address the comments from this code review:

## Overall Comments
- The EMSCRIPTEN-specific global state for WebGL context tracking in mapcanvas_gl.cpp (g_wasmInitialized, g_wasmContextLost, g_wasmInitAttempts) would be easier to reason about and test if it lived in a dedicated struct/namespace or as MapCanvas static members instead of file-level globals.
- There is a lot of duplicated logic between the QOpenGLWidget and QOpenGLWindow code paths (e.g. MakeCurrentRaii, width/height/rect wrappers, event forwarding); consider factoring out common behavior behind small helpers or templates to reduce the number of #ifdef __EMSCRIPTEN__ branches.
- The new scripts/build-wasm.sh hardcodes local paths for emsdk and Qt; making these configurable via environment variables or script arguments would avoid breakage for other environments and CI.

## Individual Comments

### Comment 1
<location> `src/display/mapcanvas_gl.cpp:237-239` </location>
<code_context>

+// WASM: Track initialization and context state globally
+#ifdef __EMSCRIPTEN__
+static bool g_wasmInitialized = false;
+static std::atomic<bool> g_wasmContextLost{false};
+static std::atomic<int> g_wasmInitAttempts{0};
+#endif
+
</code_context>

<issue_to_address>
**issue (bug_risk):** Global WASM context flags are shared across all MapCanvas instances and never reset.

These globals are process-wide. If more than one MapCanvas is created over the app’s lifetime, later instances will see `g_wasmInitialized == true` and skip `initializeGL()`, remaining uninitialized. Likewise, a single context loss sets `g_wasmContextLost` for all instances with no way to recover. Please scope these flags to MapCanvas (as members) or add a lifecycle-tied reset mechanism.
</issue_to_address>

### Comment 2
<location> `scripts/build-wasm.sh:4-11` </location>
<code_context>
+
+# Source Emscripten environment
+# IMPORTANT: Change this path to match your emsdk installation location
+source "$HOME/dev/emsdk/emsdk_env.sh"
+
+# Paths - automatically detect project root (parent of scripts directory)
+MMAPPER_SRC="$(cd "$(dirname "$0")/.." && pwd)"
+QT_WASM="$HOME/Qt/6.10.2/wasm_multithread"
+QT_HOST="$HOME/Qt/6.10.2/macos"
+
+# Configure with qt-cmake
</code_context>

<issue_to_address>
**suggestion:** Hardcoded local paths in build-wasm.sh reduce portability and maintainability.

The script hardcodes `$HOME/dev/emsdk/emsdk_env.sh` and specific Qt versions/paths, which hurts reuse across machines and CI. Consider making these paths configurable via environment variables or script arguments (with reasonable defaults) so users don’t need to edit the script locally.

```suggestion
# Source Emscripten environment
# You can override EMSDK_ENV to point to your emsdk_env.sh, otherwise a default under $HOME is used.
: "${EMSDK_ENV:="$HOME/dev/emsdk/emsdk_env.sh"}"
if [ ! -f "$EMSDK_ENV" ]; then
    echo "ERROR: Emscripten environment script not found at '$EMSDK_ENV'." >&2
    echo "Set EMSDK_ENV to your emsdk_env.sh path before running this script." >&2
    exit 1
fi
# shellcheck source=/dev/null
source "$EMSDK_ENV"

# Paths - automatically detect project root (parent of scripts directory)
MMAPPER_SRC="$(cd "$(dirname "$0")/.." && pwd)"

# You can override QT_WASM and QT_HOST to match your Qt installation.
: "${QT_WASM:="$HOME/Qt/6.10.2/wasm_multithread"}"
: "${QT_HOST:="$HOME/Qt/6.10.2/macos"}"
```
</issue_to_address>

Sourcery is free for open source - if you like our reviews please consider sharing them ✨
Help me be more useful! Please click 👍 or 👎 on each comment and I'll use the feedback to improve your reviews.

@codecov
Copy link

codecov bot commented Feb 12, 2026

Codecov Report

❌ Patch coverage is 3.33333% with 58 lines in your changes missing coverage. Please review.
✅ Project coverage is 25.85%. Comparing base (26d1a9d) to head (f9badce).
⚠️ Report is 191 commits behind head on master.

Files with missing lines Patch % Lines
src/display/MapCanvasData.h 0.00% 20 Missing ⚠️
src/display/mapwindow.cpp 0.00% 18 Missing ⚠️
src/display/mapcanvas.h 0.00% 7 Missing ⚠️
src/display/mapcanvas_gl.cpp 0.00% 5 Missing ⚠️
src/opengl/legacy/Legacy.cpp 0.00% 5 Missing ⚠️
src/display/MapCanvasRoomDrawer.cpp 0.00% 3 Missing ⚠️
Additional details and impacted files
@@             Coverage Diff             @@
##           master     #455       +/-   ##
===========================================
- Coverage   66.48%   25.85%   -40.63%     
===========================================
  Files          85      492      +407     
  Lines        4186    40725    +36539     
  Branches      255     4415     +4160     
===========================================
+ Hits         2783    10531     +7748     
- Misses       1403    30194    +28791     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@nschimme
Copy link
Contributor

Could we move the gesture handling to the MapWindow as it continues to be a widget?

@KasparMetsa
Copy link
Contributor Author

KasparMetsa commented Feb 12, 2026

Could we move the gesture handling to the MapWindow as it continues to be a widget?

Moved pinch-to-zoom gesture handling from MapCanvas to MapWindow.

@KasparMetsa
Copy link
Contributor Author

@sourcery-ai review

Copy link

@sourcery-ai sourcery-ai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hey - I've found 2 issues, and left some high level feedback:

  • In MapWindow::hideCanvas under __EMSCRIPTEN__ the hide argument is ignored, so callers lose the ability to hide/show the canvas; consider forwarding this to the container widget (e.g., getCanvas()->getContainerWidget()->setVisible(!hide)) or documenting this limitation explicitly.
  • The new SizeSource can silently return zero sizes or an empty QRect when neither a QWidget nor QWindow is set; adding an assertion or explicit guard when both pointers are null would make misuse easier to detect.
  • For consistency with the rest of the codebase, the new qDebug/qWarning logging in WASM-specific branches (e.g., VAO::emplace, OpenGL::initializeRenderer, generateMapDataFinisher) might be better routed through the existing logging utilities so logging behavior stays uniform across platforms.
Prompt for AI Agents
Please address the comments from this code review:

## Overall Comments
- In `MapWindow::hideCanvas` under `__EMSCRIPTEN__` the `hide` argument is ignored, so callers lose the ability to hide/show the canvas; consider forwarding this to the container widget (e.g., `getCanvas()->getContainerWidget()->setVisible(!hide)`) or documenting this limitation explicitly.
- The new `SizeSource` can silently return zero sizes or an empty `QRect` when neither a `QWidget` nor `QWindow` is set; adding an assertion or explicit guard when both pointers are null would make misuse easier to detect.
- For consistency with the rest of the codebase, the new `qDebug`/`qWarning` logging in WASM-specific branches (e.g., `VAO::emplace`, `OpenGL::initializeRenderer`, `generateMapDataFinisher`) might be better routed through the existing logging utilities so logging behavior stays uniform across platforms.

## Individual Comments

### Comment 1
<location> `src/display/mapcanvas_gl.cpp:286-287` </location>
<code_context>
+#endif
         doneCurrent();
-        QMessageBox::critical(this,
+        QMessageBox::critical(nullptr,
                               "Unable to initialize OpenGL",
                               "Upgrade your video card drivers");
         if constexpr (CURRENT_PLATFORM == PlatformEnum::Windows) {
</code_context>

<issue_to_address>
**issue (bug_risk):** Using nullptr as QMessageBox parent changes modality/positioning on desktop; consider keeping `this` except where it cannot be used (e.g. WASM).

This change makes the dialog a top-level window, which can end up behind other windows or on another screen, regressing the existing UX. If this is for WASM, consider keeping `this` on native builds and only using `nullptr` (or omitting the dialog) under `__EMSCRIPTEN__` so desktop behavior remains unchanged.
</issue_to_address>

### Comment 2
<location> `src/display/mapcanvas_gl.cpp:52-59` </location>
<code_context>
+        : m_sizeSource{sizeSource}
+    {}
+
+#ifdef __EMSCRIPTEN__
+    explicit MapCanvasViewport(QWindow &sizeSource)
+        : m_sizeSource{sizeSource}
</code_context>

<issue_to_address>
**suggestion (bug_risk):** Reinitialization path on WASM sets context-lost flag but does not log or attempt any recovery, which may make failures opaque.

On WASM, when `initializeGL()` sees `s_wasmInitialized` already true, it just sets `s_wasmContextLost` and returns. This effectively becomes a silent no-op: no log and no call to something like `resetWasmContextState()`. That can make post–context-loss failures hard to diagnose. Please add at least a warning log here and consider a documented recovery path that safely calls `resetWasmContextState()` before retrying initialization.
</issue_to_address>

Sourcery is free for open source - if you like our reviews please consider sharing them ✨
Help me be more useful! Please click 👍 or 👎 on each comment and I'll use the feedback to improve your reviews.

Comment on lines +286 to 287
QMessageBox::critical(nullptr,
"Unable to initialize OpenGL",
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

issue (bug_risk): Using nullptr as QMessageBox parent changes modality/positioning on desktop; consider keeping this except where it cannot be used (e.g. WASM).

This change makes the dialog a top-level window, which can end up behind other windows or on another screen, regressing the existing UX. If this is for WASM, consider keeping this on native builds and only using nullptr (or omitting the dialog) under __EMSCRIPTEN__ so desktop behavior remains unchanged.

Comment on lines +52 to 59
#ifdef __EMSCRIPTEN__
#include <QOpenGLWindow>
#else
#include <QOpenGLWidget>
#endif
#include <QtCore>
#include <QtGui/qopengl.h>
#include <QtGui>
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

suggestion (bug_risk): Reinitialization path on WASM sets context-lost flag but does not log or attempt any recovery, which may make failures opaque.

On WASM, when initializeGL() sees s_wasmInitialized already true, it just sets s_wasmContextLost and returns. This effectively becomes a silent no-op: no log and no call to something like resetWasmContextState(). That can make post–context-loss failures hard to diagnose. Please add at least a warning log here and consider a documented recovery path that safely calls resetWasmContextState() before retrying initialization.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants