Skip to content

fix: use QQuickOpenGLUtils to reset OpenGL state#773

Open
zzxyb wants to merge 1 commit intolinuxdeepin:masterfrom
zzxyb:render
Open

fix: use QQuickOpenGLUtils to reset OpenGL state#773
zzxyb wants to merge 1 commit intolinuxdeepin:masterfrom
zzxyb:render

Conversation

@zzxyb
Copy link
Collaborator

@zzxyb zzxyb commented Mar 9, 2026

Summary by Sourcery

Bug Fixes:

  • Replace manual OpenGL state cleanup with QQuickOpenGLUtils::resetOpenGLState() to avoid incorrect or incomplete GL state restoration.

@deepin-ci-robot
Copy link

[APPROVALNOTIFIER] This PR is NOT APPROVED

This pull-request has been approved by: zzxyb

The full list of commands accepted by this bot can be found here.

Details Needs approval from an approver in each of these files:

Approvers can indicate their approval by writing /approve in a comment
Approvers can cancel approval by writing /approve cancel in a comment

@zzxyb zzxyb changed the title fix: crash inqsgnode fix: crash in qsg Mar 9, 2026
@sourcery-ai
Copy link

sourcery-ai bot commented Mar 9, 2026

Reviewer's guide (collapsed on small PRs)

Reviewer's Guide

Refactors the OpenGL state reset logic for QSGRendererInterface::OpenGL outputs to use Qt’s QQuickOpenGLUtils helper instead of manually unbinding buffers and disabling depth testing, relying on Qt’s centralized state restoration.

Sequence diagram for OpenGL state reset using QQuickOpenGLUtils

sequenceDiagram
    participant WOutputRenderWindow
    participant resetGlState
    participant WRenderHelper
    participant QSGRendererInterface
    participant QQuickOpenGLUtils

    WOutputRenderWindow->>resetGlState: invoke()
    resetGlState->>WRenderHelper: getGraphicsApi()
    WRenderHelper-->>resetGlState: graphicsApi
    alt graphicsApi is OpenGL
        resetGlState->>QSGRendererInterface: OpenGL (enum value)
        resetGlState->>QQuickOpenGLUtils: resetOpenGLState()
        QQuickOpenGLUtils-->>resetGlState: OpenGL state reset
    else graphicsApi is not OpenGL
        resetGlState-->>WOutputRenderWindow: no operation
    end
    resetGlState-->>WOutputRenderWindow: return
Loading

Class diagram for OpenGL state reset refactor

classDiagram
    class WOutputRenderWindow {
    }

    class WRenderHelper {
        +static QSGRendererInterface::GraphicsApi getGraphicsApi()
    }

    class QSGRendererInterface {
        <<enum>>
        OpenGL
        Software
        Vulkan
        Metal
        Direct3D11
    }

    class QQuickOpenGLUtils {
        +static void resetOpenGLState()
    }

    class GlobalFunctions {
        +static void resetGlState()
    }

    GlobalFunctions ..> WRenderHelper : uses
    GlobalFunctions ..> QSGRendererInterface : checksGraphicsApi
    GlobalFunctions ..> QQuickOpenGLUtils : calls
    WOutputRenderWindow ..> GlobalFunctions : calls resetGlState()
Loading

File-Level Changes

Change Details Files
Use QQuickOpenGLUtils to reset OpenGL state instead of manual gl* calls.
  • Include QQuickOpenGLUtils header in the output render window implementation.
  • Replace manual glBindBuffer and glDisable calls in resetGlState() with a single QQuickOpenGLUtils::resetOpenGLState() invocation when using the OpenGL graphics API.
waylib/src/server/qtquick/woutputrenderwindow.cpp

Possibly linked issues

  • #(no explicit number provided): PR changes resetGlState() in WOutputRenderWindow, addressing the rendering/scenegraph crash shown in the stack trace.

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 1 issue, and left some high level feedback:

  • Consider guarding the node->markDirty(QSGNode::DirtyNodeRemoved); call with a null check to avoid dereferencing a null pointer when updatePaintNode is invoked with node == nullptr.
Prompt for AI Agents
Please address the comments from this code review:

## Overall Comments
- Consider guarding the `node->markDirty(QSGNode::DirtyNodeRemoved);` call with a null check to avoid dereferencing a null pointer when `updatePaintNode` is invoked with `node == nullptr`.

## Individual Comments

### Comment 1
<location path="waylib/src/server/qtquick/wquickcursor.cpp" line_range="578" />
<code_context>
     // Ignore the tp->proxy, Don't use tp->qwBuffer()
     if (!tp->buffer) {
-        delete node;
+        node->markDirty(QSGNode::DirtyNodeRemoved);
         return nullptr;
     }
</code_context>
<issue_to_address>
**issue (bug_risk):** Guard against null `node` and clarify ownership/lifetime when replacing `delete` with `markDirty`.

`delete node;` was safe for null and freed the node. The new `node->markDirty(...)` will crash if `node` is null (e.g. on first call), and `markDirty(QSGNode::DirtyNodeRemoved)` does not itself destroy the node. Please guard the call, e.g. `if (node) node->markDirty(QSGNode::DirtyNodeRemoved);`, and verify that the scene graph will delete a root node that is only marked removed but returned as `nullptr`, or otherwise restore explicit deletion to avoid a leak.
</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.

@zzxyb zzxyb marked this pull request as draft March 9, 2026 02:01
@zzxyb zzxyb force-pushed the render branch 2 times, most recently from 0e259e2 to 1e954ef Compare March 13, 2026 05:23
Replace manual OpenGL state reset with QQuickOpenGLUtils::resetOpenGLState()
to properly restore the Qt Quick rendering state.

Log:

Influence:
@zzxyb zzxyb changed the title fix: crash in qsg fix: use QQuickOpenGLUtils to reset OpenGL state Mar 19, 2026
@zzxyb zzxyb marked this pull request as ready for review March 19, 2026 01:40
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 reviewed your changes and they look great!


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.

@zzxyb zzxyb requested a review from zccrs March 19, 2026 01:44
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.

2 participants