Skip to content

fix: skip screencap when all next nodes use DirectHit#1282

Open
MistEO wants to merge 1 commit intomainfrom
fix/skip-screencap-for-direct-hit
Open

fix: skip screencap when all next nodes use DirectHit#1282
MistEO wants to merge 1 commit intomainfrom
fix/skip-screencap-for-direct-hit

Conversation

@MistEO
Copy link
Copy Markdown
Member

@MistEO MistEO commented Apr 17, 2026

Summary

  • When all enabled nodes in the next list use DirectHit recognition, skip the screencap() call entirely
  • DirectHit does not require image data — correct_roi already handles empty images gracefully
  • This allows non-visual pipeline tasks (e.g. Custom actions like Kill Self / Sleep / Webhook) to execute even when the controller is disconnected or unavailable

Background

Downstream projects like MXU (MaaEnd) use DirectHit + Custom Action for non-visual tasks such as process management, sleep, and notifications. When a preceding task disconnects the controller (e.g. killing the game process), subsequent DirectHit tasks would get stuck in the screencap-retry loop until timeout, even though they never need a screenshot.

Related: MaaEnd/MaaEnd#2109

Test plan

  • Verify normal pipeline execution with screenshot-dependent nodes (TemplateMatch, OCR, etc.) is unaffected
  • Verify DirectHit + Custom action nodes work without a connected controller
  • Verify mixed next lists (some DirectHit, some not) still require screencap

Made with Cursor

Summary by Sourcery

错误修复:

  • 防止仅用于 DirectHit 的流水线步骤在控制器断开连接或无法获取屏幕截图时,卡在截屏重试循环中而无法继续执行。
Original summary in English

Summary by Sourcery

Bug Fixes:

  • Prevent DirectHit-only pipeline steps from stalling in the screencap retry loop when the controller is disconnected or screenshots are unavailable.

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
Copilot AI review requested due to automatic review settings April 17, 2026 09:35
Copy link
Copy Markdown
Contributor

@sourcery-ai sourcery-ai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

嗨——我已经审查了你的更改,一切看起来都很棒!


Sourcery 对开源项目是免费的——如果你觉得我们的评审有帮助,请考虑分享它们 ✨
帮我变得更有用!请在每条评论上点 👍 或 👎,我会根据你的反馈改进后续的代码审查。
Original comment in English

Hey - I've reviewed your changes and they look great!


Sourcery is free for open source - if you like our reviews please consider sharing them ✨
Help me be more useful! Please click 👍 or 👎 on each comment and I'll use the feedback to improve your reviews.

Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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 next node requires image-based recognition; if not, avoid calling screencap().
  • Gate the existing “screencap failed” retry behavior behind need_screencap.

Comment on lines +164 to +167
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;
});
Copy link

Copilot AI Apr 17, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Copilot uses AI. Check for mistakes.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants