fix(dde-lowpower): fix null pointer crash when screenAt returns null … - #442
Conversation
…on Wayland 1. Added null check for QScreen pointer returned by screenAt(QCursor::pos()) 2. Fallback to primaryScreen() when screenAt fails on Wayland 3. Early return if no screen available at all 4. Prevents SIGSEGV when QCursor::pos() returns invalid position Log: Fix dde-lowpower crash on Wayland due to null screen pointer Influence: Fixes crash on Wayland when launching with --quit fix(dde-lowpower): 修复 Wayland 下 screenAt 返回空指针导致的崩溃 1. 增加 screenAt 返回空指针的判空保护 2. 获取不到光标所在屏幕时降级到主屏 3. 所有屏幕都不可用时提前返回 4. 避免 QCursor::pos() 返回无效位置时触发 SIGSEGV Log: 修复 Wayland 下 dde-lowpower 空指针崩溃 PMS: BUG-370187 Influence: 修复 Wayland 下启动崩溃
deepin pr auto review★ 总体评分:95分■ 【总体评价】
■ 【详细分析】
■ 【改进建议代码示例】 // SPDX-FileCopyrightText: 2015 - 2023 UnionTech Software Technology Co., Ltd.
//
// SPDX-License-Identifier: GPL-3.0-or-later
// ... 原有代码 ...
void Window::setupSize()
{
setFixedSize(totalWidth, totalHeight);
QScreen *screen = qApp->screenAt(QCursor::pos());
if (!screen) {
screen = qApp->primaryScreen();
}
if (!screen) {
return;
}
const qreal ratio = screen->devicePixelRatio();
m_image->setFixedSize(m_pix.size() / ratio);
m_image->move(screen->geometry().center() - m_image->rect().center());
} |
|
[APPROVALNOTIFIER] This PR is NOT APPROVED This pull-request has been approved by: mhduiy, robertkill The full list of commands accepted by this bot can be found here. DetailsNeeds approval from an approver in each of these files:Approvers can indicate their approval by writing |
There was a problem hiding this comment.
Hey - I've left some high level feedback:
- In the early-return case when no screen is found,
setupSize()exits after setting the window’s fixed size but before sizing/positioningm_image; consider either documenting this behavior or providing a sensible fallback (e.g., centering within a default rect) to avoid partially initialized layout. - If the intent is specifically to handle Wayland quirks, it might be helpful to add a short comment above the
screenAt/primaryScreenlogic explaining why both are tried and why an early return is acceptable when both fail, to aid future maintainers.
Prompt for AI Agents
Please address the comments from this code review:
## Overall Comments
- In the early-return case when no screen is found, `setupSize()` exits after setting the window’s fixed size but before sizing/positioning `m_image`; consider either documenting this behavior or providing a sensible fallback (e.g., centering within a default rect) to avoid partially initialized layout.
- If the intent is specifically to handle Wayland quirks, it might be helpful to add a short comment above the `screenAt`/`primaryScreen` logic explaining why both are tried and why an early return is acceptable when both fail, to aid future maintainers.Help me be more useful! Please click 👍 or 👎 on each comment and I'll use the feedback to improve your reviews.
…on Wayland
Log: Fix dde-lowpower crash on Wayland due to null screen pointer
Influence: Fixes crash on Wayland when launching with --quit
fix(dde-lowpower): 修复 Wayland 下 screenAt 返回空指针导致的崩溃
Log: 修复 Wayland 下 dde-lowpower 空指针崩溃
PMS: BUG-370187
Influence: 修复 Wayland 下启动崩溃
Summary by Sourcery
Handle missing screen information more safely when sizing the low-power window to prevent crashes on Wayland.
Bug Fixes:
Enhancements: