Skip to content

fix: buffer assignment error with clang build#739

Open
zorowk wants to merge 1 commit intolinuxdeepin:masterfrom
zorowk:fix_icon
Open

fix: buffer assignment error with clang build#739
zorowk wants to merge 1 commit intolinuxdeepin:masterfrom
zorowk:fix_icon

Conversation

@zorowk
Copy link
Contributor

@zorowk zorowk commented Feb 10, 2026

Clang rejects assigning qw_buffer to a Q_PROPERTY of type qw_buffer* in QML, causing runtime errors like:

Unable to assign qw_buffer to qw_buffer*

Change the buffer property to QObject* and cast back to qw_buffer in C++, allowing QML to pass the buffer through bindings correctly.

This fixes incorrect rendering when opening PrelaunchSplash.

Issue: Fixes #737
Log: fixes incorrect icon rendering when opening PrelaunchSplash.
Influence: Launching the application for the first time

Summary by Sourcery

Adjust buffer property exposure for WBufferItem to resolve QML buffer assignment issues with clang builds.

Bug Fixes:

  • Allow WBufferItem buffer to be passed through QML bindings without type errors by exposing it as QObject* and casting internally.
  • Prevent runtime errors and incorrect icon rendering when opening PrelaunchSplash caused by failed qw_buffer* assignments in QML.

Enhancements:

  • Simplify type registration by removing the qw_buffer* meta-type registration from application startup.

@deepin-ci-robot
Copy link

[APPROVALNOTIFIER] This PR is NOT APPROVED

This pull-request has been approved by: zorowk

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

@sourcery-ai
Copy link

sourcery-ai bot commented Feb 10, 2026

Reviewer's guide (collapsed on small PRs)

Reviewer's Guide

Adjusts the WBufferItem QML-exposed buffer property to use QObject* instead of qw_buffer* and performs casting/validation inside C++, fixing Clang/QML type assignment issues and removing the now-unneeded qw_buffer* meta-type registration.

Sequence diagram for buffer assignment from QML to WBufferItem

sequenceDiagram
    actor User
    participant QML as QML_Engine
    participant BufferItem as WBufferItem
    participant BufferObj as qw_buffer
    participant TextureProvider as WBufferItemTextureProvider

    User->>QML: Open_PrelaunchSplash
    QML->>BufferObj: Create_qw_buffer
    QML->>BufferItem: set_property_buffer(BufferObj_as_QObject)
    BufferItem->>BufferItem: setBuffer(QObject_buffer)
    BufferItem->>BufferItem: ibuffer = qobject_cast_qw_buffer(QObject_buffer)
    alt ibuffer_is_null
        BufferItem-->>BufferItem: return_without_changes
    else ibuffer_is_valid
        BufferItem->>BufferItem: h = ibuffer.handle()
        alt invalid_handle_or_size
            BufferItem-->>BufferItem: log_warning_and_return
        else valid_handle
            BufferItem->>BufferObj: ibuffer.lock()
            BufferItem->>BufferItem: d.buffer.reset(ibuffer)
            BufferItem->>TextureProvider: setBuffer(d.buffer.get())
        end
    end
Loading

Updated class diagram for WBufferItem buffer property

classDiagram
    class WBufferItem {
        +WBufferItem(parent QQuickItem)
        +~WBufferItem()
        +QObject buffer() const
        +void setBuffer(buffer QObject)
        +bool isTextureProvider() const
        +QSGTextureProvider textureProvider() const
    }

    class qw_buffer {
        +void lock()
        +Handle handle() const
    }

    class WBufferItemPrivate {
        +std_unique_ptr~qw_buffer~ buffer
        +WBufferItemTextureProvider* textureProvider
    }

    class WBufferItemTextureProvider {
        +void setBuffer(buffer qw_buffer)
    }

    WBufferItem --> WBufferItemPrivate : uses
    WBufferItemPrivate --> qw_buffer : owns
    WBufferItemPrivate --> WBufferItemTextureProvider : uses
    WBufferItemTextureProvider --> qw_buffer : uses

    class QQuickItem
    WBufferItem --|> QQuickItem

    class QObject
    WBufferItem --> QObject : exposes_buffer_as_QObject
    qw_buffer --|> QObject

    class Handle {
        +int width
        +int height
    }

    qw_buffer --> Handle : returns_handle
Loading

File-Level Changes

Change Details Files
Expose WBufferItem::buffer as a generic QObject* in QML and handle casting to qw_buffer internally.
  • Change the Q_PROPERTY type of buffer from qw_buffer* to QObject* while keeping the same accessor names/signature from QML’s perspective.
  • Update WBufferItem::buffer() to return QObject* while still returning the stored d->buffer.get() pointer.
  • Update WBufferItem::setBuffer to accept QObject*, cast it to qw_buffer* with qobject_cast, and early-return if the effective qw_buffer* is unchanged.
  • Use the cast qw_buffer* (ibuffer) for handle() validation, locking, and storage instead of operating directly on the QObject* argument.
  • Ensure the internal texture provider uses the stored qw_buffer* after the cast and reset.
waylib/src/server/qtquick/wbufferitem.h
waylib/src/server/qtquick/wbufferitem.cpp
Remove redundant meta-type registration for qw_buffer* now that QML sees the property as QObject*.
  • Delete qRegisterMetaType registration of qw_buffer* in main.cpp since QML no longer directly uses qw_buffer* as a property type.
src/main.cpp

Assessment against linked issues

Issue Objective Addressed Explanation
#737 Fix the QML runtime error Unable to assign qw_buffer to qw_buffer* when binding the buffer property used by PrelaunchSplash.
#737 Restore correct rendering of the splash screen icon when first opening the application.

Possibly linked issues


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:

  • When casting the QObject* back to qw_buffer* in setBuffer, consider logging or otherwise handling the case where qobject_cast fails so that accidental assignment of an incompatible QObject does not silently clear the current buffer.
  • Now that the QML property is typed as QObject*, it may be worth documenting or enforcing (e.g., via a runtime check) that only qw_buffer instances are expected, to avoid misuse from QML or future C++ callers.
Prompt for AI Agents
Please address the comments from this code review:

## Overall Comments
- When casting the `QObject*` back to `qw_buffer*` in `setBuffer`, consider logging or otherwise handling the case where `qobject_cast` fails so that accidental assignment of an incompatible QObject does not silently clear the current buffer.
- Now that the QML property is typed as `QObject*`, it may be worth documenting or enforcing (e.g., via a runtime check) that only `qw_buffer` instances are expected, to avoid misuse from QML or future C++ callers.

## Individual Comments

### Comment 1
<location> `waylib/src/server/qtquick/wbufferitem.cpp:102-111` </location>
<code_context>
     W_D(WBufferItem);

-    if (d->buffer.get() == buffer)
+    QW_NAMESPACE::qw_buffer *ibuffer = qobject_cast<QW_NAMESPACE::qw_buffer*>(buffer);
+    if (d->buffer.get() == ibuffer)
         return;
</code_context>

<issue_to_address>
**issue (bug_risk):** Passing a non-`qw_buffer` QObject clears the current buffer silently, which may be unintended.

With the `QObject*` API, passing a non-`qw_buffer` object makes `ibuffer` null, so `d->buffer.reset(ibuffer)` drops the existing buffer while effectively ignoring the new argument. This is surprising for callers and hard to debug. Consider either returning early when `buffer` is non-null but `ibuffer` is null (keeping the existing buffer) and/or logging a warning in that case so the behavior is explicit and valid buffers aren’t discarded due to a type mismatch.
</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.

wineee
wineee previously approved these changes Feb 10, 2026
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

This PR addresses a clang/QML runtime type assignment issue that prevented PrelaunchSplash from rendering correctly by changing how qw_buffer is exposed to QML through Waylib’s WBufferItem.

Changes:

  • Expose WBufferItem::buffer to QML as QObject* instead of QW_NAMESPACE::qw_buffer*, and cast back internally in C++.
  • Update WBufferItem getter/setter implementations to work with QObject* while still operating on qw_buffer.
  • Remove the explicit qRegisterMetaType<QW_NAMESPACE::qw_buffer*>("qw_buffer*") call from application startup.

Reviewed changes

Copilot reviewed 3 out of 3 changed files in this pull request and generated 1 comment.

File Description
waylib/src/server/qtquick/wbufferitem.h Changes the QML-facing buffer property type to QObject* to avoid QML assignment failures.
waylib/src/server/qtquick/wbufferitem.cpp Implements the QObject* setter/getter and casts to qw_buffer* internally for rendering/locking.
src/main.cpp Removes explicit qw_buffer* metatype registration during startup.

Clang rejects assigning qw_buffer to a Q_PROPERTY of type qw_buffer* in
QML, causing runtime errors like:

  Unable to assign qw_buffer to qw_buffer*

Change the buffer property to QObject* and cast back to qw_buffer in
C++, allowing QML to pass the buffer through bindings correctly.

This fixes incorrect rendering when opening PrelaunchSplash.

Issue: Fixes linuxdeepin#737
Log: fixes incorrect icon rendering when opening PrelaunchSplash.
Influence: Launching the application for the first time
QGuiApplication::setQuitOnLastWindowClosed(false);

QGuiApplication app(argc, argv);
qRegisterMetaType<QW_NAMESPACE::qw_buffer*>("qw_buffer*");
Copy link
Member

Choose a reason for hiding this comment

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

用 Q_DECLARE_METATYPE 代替可以吗?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

我实验了一下,不行 qw_buffer和qw_buffer*都试过不行

modified   qwlroots/src/types/qwbuffer.h
@@ -57,3 +57,4 @@ public:
 };
 
 QW_END_NAMESPACE
+Q_DECLARE_METATYPE(QW_NAMESPACE::qw_buffer)   **qw_buffer和qw_buffer*都试过不行**
modified   src/main.cpp
@@ -29,7 +29,7 @@ int main(int argc, char *argv[])
     QGuiApplication::setQuitOnLastWindowClosed(false);
 
     QGuiApplication app(argc, argv);
-    qRegisterMetaType<QW_NAMESPACE::qw_buffer*>("qw_buffer*");
+    //qRegisterMetaType<QW_NAMESPACE::qw_buffer*>("qw_buffer*");
 
     app.setOrganizationName("deepin");
     app.setApplicationName("treeland");
modified   src/modules/prelaunch-splash/prelaunchsplash.h
@@ -22,7 +22,7 @@ QW_BEGIN_NAMESPACE
 class qw_display;
 class qw_buffer;
 QW_END_NAMESPACE
-Q_DECLARE_OPAQUE_POINTER(QW_NAMESPACE::qw_buffer*)
+//Q_DECLARE_OPAQUE_POINTER(QW_NAMESPACE::qw_buffer*)  **这里不注释会和Q_DECLARE_METATYPE产生冲突**
 
 class PrelaunchSplashPrivate;
 struct wl_global;

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.

[Bug]: 应用程序启动闪屏界面没有正确显示图标 同时日志中出现qml qw_BUFFER转换错误

4 participants