fix: skip screencap when all next nodes use DirectHit#1282
fix: skip screencap when all next nodes use DirectHit#1282
Conversation
DirectHit does not require image data, so avoid calling screencap() when every enabled node in the next list uses DirectHit. This allows non-visual pipeline tasks (e.g. Custom actions) to proceed even when the controller is disconnected or unavailable. Made-with: Cursor
There was a problem hiding this comment.
嗨——我已经审查了你的更改,一切看起来都很棒!
帮我变得更有用!请在每条评论上点 👍 或 👎,我会根据你的反馈改进后续的代码审查。
Original comment in English
Hey - I've reviewed your changes and they look great!
Help me be more useful! Please click 👍 or 👎 on each comment and I'll use the feedback to improve your reviews.
There was a problem hiding this comment.
Pull request overview
This PR optimizes pipeline execution by skipping screenshot capture when all enabled next nodes use DirectHit recognition, allowing non-visual tasks to proceed even if the controller cannot provide screenshots.
Changes:
- Detect whether any enabled
nextnode requires image-based recognition; if not, avoid callingscreencap(). - Gate the existing “screencap failed” retry behavior behind
need_screencap.
| const bool need_screencap = !std::ranges::all_of(next, [&](const MAA_RES_NS::NodeAttr& node) { | ||
| auto data_opt = context_->get_pipeline_data(node); | ||
| return !data_opt || !data_opt->enabled || data_opt->reco_type == MAA_RES_NS::Recognition::Type::DirectHit; | ||
| }); |
There was a problem hiding this comment.
need_screencap calls context_->get_pipeline_data(node) for every entry in next, but the function is also called just above in the valid check. Because get_pipeline_data() logs warnings on missing nodes, this can double-log and also does two lookups per node. Consider iterating next once and computing both valid and need_screencap (and/or caching the resolved PipelineData/enabled/reco_type) to avoid repeated lookups/log noise.
Summary
nextlist useDirectHitrecognition, skip thescreencap()call entirelyDirectHitdoes not require image data —correct_roialready handles empty images gracefullyCustomactions like Kill Self / Sleep / Webhook) to execute even when the controller is disconnected or unavailableBackground
Downstream projects like MXU (MaaEnd) use
DirectHit+Custom Actionfor non-visual tasks such as process management, sleep, and notifications. When a preceding task disconnects the controller (e.g. killing the game process), subsequentDirectHittasks would get stuck in the screencap-retry loop until timeout, even though they never need a screenshot.Related: MaaEnd/MaaEnd#2109
Test plan
DirectHit+Customaction nodes work without a connected controllernextlists (some DirectHit, some not) still require screencapMade with Cursor
Summary by Sourcery
错误修复:
Original summary in English
Summary by Sourcery
Bug Fixes: