Skip to content

Conversation

@zorowk
Copy link

@zorowk zorowk commented Dec 26, 2025

…s too early

Add null checks for surface->parentItem() and container before calling container->childItems().indexOf(surface). This avoids dereferencing an incompletely initialized QQuickItem when a new surface is added to the model but has not yet been fully inserted into the scene graph.

Returning INT_MAX as a fallback sort order places unready surfaces at the end of the list, ensuring stable behavior until the item is properly parented and polished.

issue: #659
comment: #659 (comment)

Summary by Sourcery

Bug Fixes:

  • Prevent a crash in SurfaceListModel::data by handling cases where a surface has no parent item or container during initial sort order calculation.

@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 Dec 26, 2025

Reviewer's guide (collapsed on small PRs)

Reviewer's Guide

Adds defensive null checks in SurfaceListModel::data for the InitialSortOrderRole to avoid dereferencing incompletely initialized QQuickItem instances, and falls back to INT_MAX as the sort order for surfaces whose parent/container is not yet ready.

Class diagram for updated SurfaceListModel::data null-check behavior

classDiagram
    class SurfaceListModel {
        +data(index QModelIndex, role int) QVariant
        +surfaces() QList~Surface*~
    }

    class Surface {
        +parentItem() QQuickItem*
        +container() QQuickItem*
    }

    class QQuickItem {
        +childItems() QList~QQuickItem*~
    }

    class QModelIndex
    class QVariant

    SurfaceListModel --> Surface : uses
    Surface --> QQuickItem : parentItem
    Surface --> QQuickItem : container
    QQuickItem --> QQuickItem : childItems
    SurfaceListModel --> QModelIndex : parameter
    SurfaceListModel --> QVariant : return type
Loading

File-Level Changes

Change Details Files
Harden SurfaceListModel::data against partially initialized surfaces when computing InitialSortOrderRole, falling back to a max-int sort order for unparented/uncontained items.
  • Guard access to surface->parentItem() and return INT_MAX when the parent item is null.
  • Guard access to surface->container() and return INT_MAX when the container is null.
  • Keep using container->childItems().indexOf(surface) to derive the sort index, asserting the index is non-negative for valid cases.
src/surface/surfacecontainer.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 left some high level feedback:

  • Instead of returning the magic value INT_MAX in multiple places, consider defining a named constant (e.g. kUnreadySurfaceSortOrder) or using std::numeric_limits::max() to improve readability and type safety.
  • Given that container->childItems().indexOf(surface) can theoretically return -1 even after your null checks, it may be safer to replace the Q_ASSERT with a conditional that also falls back to the default sort order rather than crashing in release builds.
Prompt for AI Agents
Please address the comments from this code review:

## Overall Comments
- Instead of returning the magic value INT_MAX in multiple places, consider defining a named constant (e.g. kUnreadySurfaceSortOrder) or using std::numeric_limits<int>::max() to improve readability and type safety.
- Given that container->childItems().indexOf(surface) can theoretically return -1 even after your null checks, it may be safer to replace the Q_ASSERT with a conditional that also falls back to the default sort order rather than crashing in release builds.

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.

…s too early

Add null checks for surface->parentItem() and container before calling
container->childItems().indexOf(surface). This avoids dereferencing an
incompletely initialized QQuickItem when a new surface is added to the
model but has not yet been fully inserted into the scene graph.

Returning INT_MAX as a fallback sort order places unready surfaces at the
end of the list, ensuring stable behavior until the item is properly
parented and polished.

issue: linuxdeepin#659
comment: linuxdeepin#659 (comment)
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