fix: prevent SVG cache tasks from outliving application - #327
18202781743 wants to merge 1 commit into
Conversation
|
[APPROVALNOTIFIER] This PR is NOT APPROVED This pull-request has been approved by: 18202781743 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 |
Reviewer's GuideThe PR prevents SVG cache-writing tasks from surviving application shutdown by using an application-owned QThreadPool that drains safely during aboutToQuit, while preserving asynchronous rendering. It also standardizes Chameleon’s Wayland detection through DGuiApplicationHelper. Sequence diagram for safe SVG cache shutdownsequenceDiagram
participant App as QCoreApplication
participant Engine as QSvgIconEngine
participant Pool as IconCachePool
participant Worker as CacheWorker
participant Plugin as QtImagePluginLoader
Engine->>Pool: instance()
Pool-->>Engine: application-owned pool
Engine->>Pool: QtConcurrent.run(pool, cache write)
Pool->>Worker: execute QSaveFile and image.save()
Worker->>Plugin: image.save()
App-->>Pool: aboutToQuit
Pool->>Pool: clear()
Pool->>Pool: waitForDone()
Worker-->>Pool: active cache job finishes
Pool-->>App: shutdown continues safely
File-Level Changes
Tips and commandsInteracting with Sourcery
Customizing Your ExperienceAccess your dashboard to:
Getting Help
|
caae49a to
c3e43c9
Compare
1. Replace the global thread pool with a dedicated IconCachePool for SVG icon cache writes 2. Tie the pool's lifetime to QCoreApplication via QPointer so it is invalidated on shutdown 3. Connect to QCoreApplication::aboutToQuit to clear pending tasks and wait for completion 4. Guard pool creation to the application's main thread and return nullptr once stopped 5. Skip cache writes entirely when no valid pool is available to avoid dangling tasks Influence: 1. Verify SVG icons still render correctly and cache files are written under normal use 2. Test application shutdown while many icon cache tasks are queued, ensure no crashes or warnings about destroyed threads 3. Confirm no tasks run on a destroyed QCoreApplication and no leaks are reported 4. Test cache file creation, commit, and timestamp updates remain functional 5. Verify behavior when pixmap rendering happens from non-main threads (pool should be skipped) 6. Check that icons without cache file paths still render without regressions fix: 防止 SVG 缓存任务超出应用生命周期 1. 使用专用的 IconCachePool 替代全局线程池来处理 SVG 图标缓存写入 2. 通过 QPointer 将线程池生命周期绑定到 QCoreApplication,在退出时自动 失效 3. 连接 QCoreApplication::aboutToQuit,清除待处理任务并等待完成 4. 限制线程池仅在应用主线程创建,停止后返回 nullptr 5. 当没有可用线程池时跳过缓存写入,避免产生悬空任务 Influence: 1. 验证正常使用下 SVG 图标仍能正确渲染并写入缓存文件 2. 测试在大量图标缓存任务排队时关闭应用,确保不会崩溃或出现线程已销毁的 警告 3. 确认不会在已销毁的 QCoreApplication 上运行任务,且无内存泄漏报告 4. 测试缓存文件的创建、提交和时间戳更新功能仍然正常 5. 验证从非主线程渲染 pixmap 时的行为(应跳过线程池) 6. 检查无缓存文件路径的图标仍能正常渲染,无回归问题
c3e43c9 to
6b4b009
Compare
deepin pr auto review🤖 AI 代码审查报告📊 总体评价
📋 提交信息
🔍 详细分析1. 语法逻辑 ✓评价: 语法正确,逻辑清晰 ✓ 评分: 25 / 25 潜在问题: 分析说明:
2. 代码质量 ✓评价: 代码结构清晰,注释完整性有提升空间 ✓ 评分: 23 / 25 潜在问题:
建议:
3. 代码性能 ✓评价: 性能良好,资源使用合理,存在一般优化空间 ✓ 评分: 17 / 20 潜在问题:
建议:
修复代码示例: // 修改前
connect(application, &QCoreApplication::aboutToQuit, this, [this] {
stopped = true;
clear();
waitForDone();
});
// 修改后
connect(application, &QCoreApplication::aboutToQuit, this, [this] {
stopped = true;
clear();
waitForDone(5000); // 最多等待 5 秒,防止极端情况下应用无法退出
});4. 代码安全 ✓评价: 存在0个安全漏洞 ✓ 评分: 30 / 30
安全漏洞详情: 分析说明:
漏洞对比统计:新增漏洞 0 个,减少漏洞 0 个,持平 0 个 💡 总结本次 PR 修复了 SVG 图标缓存写入任务在应用关闭后仍运行导致的崩溃问题。通过引入 代码设计合理,线程安全考虑周全,无安全漏洞。建议补充类级注释并为 本报告由 AI 代码审查工具自动生成 |
SVG icon cache writes run asynchronously through
QImage::save(). Duringapplication shutdown these tasks can outlive the Qt image plugin loader and
crash in
QFactoryLoader.Use an application-owned thread pool for cache writes. On
aboutToQuit, stopaccepting cache jobs, discard queued jobs, and wait for the active jobs to
finish. Normal icon rendering remains asynchronous.
Validation:
cmake --build build --target dsvgicon -j6ut_QSvgIconEngine: 7 assertions passedgit diff --checkSummary by Sourcery
Ensure SVG cache writes finish safely before the application exits.
Bug Fixes:
Enhancements: