Repository navigation
fix: prevent OCR thread cleanup crash - #108
dengzhongyuan365-dev wants to merge 1 commit into
Conversation
1. Marshal QThread finished cleanup back to MainWidget's thread. 2. Prevent reuse of a thread before its cleanup has completed. 3. Wait for a terminated OCR thread before deleting its object. Log: Prevent OCR worker thread cleanup crashes. Influence: 1. Close the OCR window while recognition is running and verify no crash. 2. Trigger repeated recognition and verify each OCR thread exits cleanly. 3. Repeat the screenshot-to-OCR flow on SW64 and x86. fix: 修复 OCR 识别线程清理竞态 1. 将 QThread finished 清理显式投递回 MainWidget 所在线程。 2. 避免在线程清理完成前复用同一个线程对象。 3. 终止 OCR 线程后等待其真正退出再删除对象。 Log: 修复 OCR 识别线程退出时的清理崩溃。 Influence: 1. OCR 识别过程中关闭窗口,验证不会崩溃。 2. 重复触发识别,验证每次 OCR 线程均可正常退出。 3. 在 SW64 和 x86 上重复截图进入 OCR 的流程。 Log: Prevent OCR worker thread cleanup crashes. Issue: V-9975 multica: V-9975
|
[APPROVALNOTIFIER] This PR is NOT APPROVED This pull-request has been approved by: dengzhongyuan365-dev 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 GuideImplementationMake destruction stop and join the OCR thread before deleting it, including after a timeout and forced termination.
Coordinate OCR thread creation, completion cleanup, reruns, and the atomic end-state across the widget and worker thread.
Tips and commandsInteracting with Sourcery
Customizing Your ExperienceAccess your dashboard to:
Getting Help
|
There was a problem hiding this comment.
Hey - I've found 1 issue
Prompt for AI Agents
Please address the comments from this code review:
## Individual Comments
### Comment 1
<location path="src/mainwidget.cpp" line_range="528" />
<code_context>
deleteLoadingUi();
- if(m_needReRunRec) {
- m_needReRunRec = false;
- runRec(false);
- }
});
</code_context>
<issue_to_address>
**New image shows stale OCR result**
When a different image is opened in the same widget while OCR is still running, `runRec(true)` returns before `OCREngine::setImage()` and records only a boolean rerun request; the finished callback calls `runRec(false)`, so the engine recognizes its previous image and displays that result for the new image.
Have the finished callback rerun OCR in a way that sets the engine's image to the newly opened image before recognition.
Also at `src/mainwidget.cpp:497-499`.
</issue_to_address>| thread->deleteLater(); | ||
|
|
||
| if (m_needReRunRec.exchange(false)) | ||
| runRec(false); |
There was a problem hiding this comment.
🟡 Medium · New image shows stale OCR result
When a different image is opened in the same widget while OCR is still running, runRec(true) returns before OCREngine::setImage() and records only a boolean rerun request; the finished callback calls runRec(false), so the engine recognizes its previous image and displays that result for the new image.
Have the finished callback rerun OCR in a way that sets the engine's image to the newly opened image before recognition.
Also at src/mainwidget.cpp:497-499.
Prompt for AI agents
In `src/mainwidget.cpp` at line 528:
**New image shows stale OCR result**
When a different image is opened in the same widget while OCR is still running, `runRec(true)` returns before `OCREngine::setImage()` and records only a boolean rerun request; the finished callback calls `runRec(false)`, so the engine recognizes its previous image and displays that result for the new image.
Have the finished callback rerun OCR in a way that sets the engine's image to the newly opened image before recognition.
Also at `src/mainwidget.cpp:497-499`.
变更说明
修复
deepin-ocr识别线程结束时可能出现的 SIGSEGV。QThread::finished清理显式投递回MainWidget所在线程。QThread对象。terminate()并再次wait()后才删除线程对象。m_isEndThread改为std::atomic_bool。根因
原实现通过无 context 的 lambda 连接
QThread::finished,lambda 实际运行在 OCR 工作线程,并直接访问、清空、删除MainWidget::m_loadImagethread。窗口关闭或重新识别时,该操作可能与主线程清理并发,对空指针或悬空线程对象调用deleteLater(),最终在QObject::deleteLater()中崩溃。SW64 上 OCR 推理较慢,更容易触发。验证计划
按用户要求,本次未在本机编译。
Multica: V-9975
Summary by Sourcery
Make OCR thread cleanup safe during shutdown and repeated recognition.
Bug Fixes:
Enhancements: