Conversation
Contributor
There was a problem hiding this comment.
Hey - 我发现了 1 个问题,并给出了一些整体性的反馈:
- 在
ActionHelper::wait_freezes中,comparator.draws()在一个左值上调用了一个&&限定的方法,按当前写法将无法编译;你可能想要的是VisionBase::save_draws(draw_name, std::move(comparator).draws());。 VisionBase::save_draws在循环中对draws中的每个元素生成的是相同的文件名,因此后面的图像可能会覆盖前面的图像;建议在格式化的文件名中追加循环索引或每张图像的 ID。
面向 AI Agent 的提示
Please address the comments from this code review:
## Overall Comments
- In `ActionHelper::wait_freezes`, `comparator.draws()` calls an `&&`-qualified method on an lvalue and will not compile as written; you likely want `VisionBase::save_draws(draw_name, std::move(comparator).draws());` instead.
- `VisionBase::save_draws` generates the same filename for every element in `draws` within the loop, so later images may overwrite earlier ones; consider appending the loop index or a per-image ID to the formatted filename.
## Individual Comments
### Comment 1
<location path="source/MaaFramework/Vision/VisionBase.cpp" line_range="90-96" />
<code_context>
+ auto dir = option.log_dir() / "vision";
+ std::filesystem::create_directories(dir);
+
+ for (const auto& draw : draws) {
+ std::string filename = std::format("{}_{}.jpg", format_now_for_filename(), name);
+ auto filepath = dir / std::filesystem::path(filename);
+
+ std::ofstream of(filepath, std::ios::out | std::ios::binary);
+ of.write(reinterpret_cast<const char*>(draw.data()), draw.size());
+ LogDebug << "save draw to" << filepath;
+ }
+}
</code_context>
<issue_to_address>
**issue (bug_risk):** Multiple draws in a single call will all use the same filename and overwrite each other.
Because `filename` is based only on `format_now_for_filename()` and `name`, every iteration in the loop writes to the same `filepath`, so only the final buffer is kept. To prevent silently overwriting earlier draws, either add a per-draw index/unique suffix to the filename or generate a single multi-image artifact instead of one file per draw.
</issue_to_address>帮我变得更有用!请在每条评论上点击 👍 或 👎,我会根据你的反馈改进后续的评审。
Original comment in English
Hey - I've found 1 issue, and left some high level feedback:
- In
ActionHelper::wait_freezes,comparator.draws()calls an&&-qualified method on an lvalue and will not compile as written; you likely wantVisionBase::save_draws(draw_name, std::move(comparator).draws());instead. VisionBase::save_drawsgenerates the same filename for every element indrawswithin the loop, so later images may overwrite earlier ones; consider appending the loop index or a per-image ID to the formatted filename.
Prompt for AI Agents
Please address the comments from this code review:
## Overall Comments
- In `ActionHelper::wait_freezes`, `comparator.draws()` calls an `&&`-qualified method on an lvalue and will not compile as written; you likely want `VisionBase::save_draws(draw_name, std::move(comparator).draws());` instead.
- `VisionBase::save_draws` generates the same filename for every element in `draws` within the loop, so later images may overwrite earlier ones; consider appending the loop index or a per-image ID to the formatted filename.
## Individual Comments
### Comment 1
<location path="source/MaaFramework/Vision/VisionBase.cpp" line_range="90-96" />
<code_context>
+ auto dir = option.log_dir() / "vision";
+ std::filesystem::create_directories(dir);
+
+ for (const auto& draw : draws) {
+ std::string filename = std::format("{}_{}.jpg", format_now_for_filename(), name);
+ auto filepath = dir / std::filesystem::path(filename);
+
+ std::ofstream of(filepath, std::ios::out | std::ios::binary);
+ of.write(reinterpret_cast<const char*>(draw.data()), draw.size());
+ LogDebug << "save draw to" << filepath;
+ }
+}
</code_context>
<issue_to_address>
**issue (bug_risk):** Multiple draws in a single call will all use the same filename and overwrite each other.
Because `filename` is based only on `format_now_for_filename()` and `name`, every iteration in the loop writes to the same `filepath`, so only the final buffer is kept. To prevent silently overwriting earlier draws, either add a per-draw index/unique suffix to the filename or generate a single multi-image artifact instead of one file per draw.
</issue_to_address>Help me be more useful! Please click 👍 or 👎 on each comment and I'll use the feedback to improve your reviews.
Contributor
There was a problem hiding this comment.
Pull request overview
This PR adds persistent debug artifacts (“draw” images) for wait_freezes comparisons and centralizes draw-file writing logic in the vision layer so multiple components can reuse it.
Changes:
- Added
VisionBase::save_draws(...)to consolidate draw saving to${log_dir}/vision. - Extended
TemplateComparatorto generate a combined side-by-side visualization (lhs/rhs + ROI + score) when draw/debug is enabled. - Threaded pipeline/node naming into
wait_freezesso saved images are attributable to the triggering node/action.
Reviewed changes
Copilot reviewed 9 out of 9 changed files in this pull request and generated 2 comments.
Show a summary per file
| File | Description |
|---|---|
| source/MaaFramework/Vision/VisionBase.h | Exposes a reusable static save_draws API. |
| source/MaaFramework/Vision/VisionBase.cpp | Implements centralized draw saving to disk. |
| source/MaaFramework/Vision/TemplateComparator.h | Declares draw_result(...) helper for visualization. |
| source/MaaFramework/Vision/TemplateComparator.cpp | Generates and stores comparator visualization draws. |
| source/MaaFramework/Task/Component/Recognizer.cpp | Refactors to use VisionBase::save_draws instead of local file-writing logic. |
| source/MaaFramework/Task/Component/Actuator.h | Extends wait_freezes signature to accept a name for draw attribution. |
| source/MaaFramework/Task/Component/Actuator.cpp | Passes pipeline node name through to wait_freezes. |
| source/MaaFramework/Task/Component/ActionHelper.h | Extends wait_freezes to accept an optional name. |
| source/MaaFramework/Task/Component/ActionHelper.cpp | Creates/saves wait_freezes comparator draws using the provided name. |
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary by Sourcery
为
wait_freezes比较添加调试可视化,并集中管理视觉调试图像的保存。New Features:
wait_freezes处理过程中,为模板比较结果生成组合调试图像。VisionBase工具,用于将编码后的视觉调试图像以带时间戳文件名的方式保存到磁盘。Enhancements:
VisionBase::save_draws辅助函数来保存 Recognizer 图像,以统一日志记录行为。wait_freezes调用中,使保存的调试图像标签更清晰。Original summary in English
Summary by Sourcery
Add debug visualization for wait_freezes comparisons and centralize saving of vision debug images.
New Features:
Enhancements: