Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: fix StopTask not work #500

Merged
merged 3 commits into from
Dec 31, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion source/MaaFramework/Task/Component/Actuator.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,9 @@ bool Actuator::run(const cv::Rect& reco_hit, MaaRecoId reco_id, const PipelineDa
break;
case Type::StopTask:
LogInfo << "Action: StopTask";
return false;
context_.need_to_stop() = true;
ret = true;
break;
default:
ret = false;
LogError << "Unknown action" << VAR(static_cast<int>(pipeline_data.action_type));
Expand Down
5 changes: 5 additions & 0 deletions source/MaaFramework/Task/Context.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -203,6 +203,11 @@ std::optional<Context::PipelineData> Context::get_pipeline_data(const std::strin
return std::nullopt;
}

bool& Context::need_to_stop()
{
return need_to_stop_;
}

bool Context::check_pipeline() const
{
if (!tasker_) {
Expand Down
3 changes: 3 additions & 0 deletions source/MaaFramework/Task/Context.h
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ class Context

public:
std::optional<PipelineData> get_pipeline_data(const std::string& task_name);
bool& need_to_stop();

private:
bool check_pipeline() const;
Expand All @@ -60,6 +61,8 @@ class Context
PipelineDataMap pipeline_override_;

private:
bool need_to_stop_ = false;

mutable std::vector<std::shared_ptr<Context>> clone_holder_;
};

Expand Down
20 changes: 14 additions & 6 deletions source/MaaFramework/Task/PipelineTask.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ bool PipelineTask::run()
PipelineData::NextList interrupt;
bool error_handling = false;

while (!next.empty() && !need_to_stop_) {
while (!next.empty() && !context_->need_to_stop()) {
cur_task_ = current.name;

size_t next_size = next.size();
Expand All @@ -44,8 +44,8 @@ bool PipelineTask::run()

auto node_detail = run_reco_and_action(list, current);

if (need_to_stop_) {
LogError << "need_to_stop" << VAR(current.name);
if (context_->need_to_stop()) {
LogWarn << "need_to_stop" << VAR(current.name);
return true;
}

Expand Down Expand Up @@ -105,14 +105,22 @@ bool PipelineTask::run()

void PipelineTask::post_stop()
{
need_to_stop_ = true;
if (!context_) {
LogError << "context is null";
return;
}
context_->need_to_stop() = true;
}

NodeDetail PipelineTask::run_reco_and_action(const PipelineData::NextList& list, const PipelineData& pretask)
{
if (!tasker_) {
LogError << "tasker is null";
return {};
}
if (!context_) {
LogError << "context is null";
return {};
}

RecoResult reco;
Expand All @@ -129,8 +137,8 @@ NodeDetail PipelineTask::run_reco_and_action(const PipelineData::NextList& list,
break;
}

if (need_to_stop_) {
LogError << "need_to_stop" << VAR(pretask.name);
if (context_->need_to_stop()) {
LogWarn << "need_to_stop" << VAR(pretask.name);
return {};
}

Expand Down
3 changes: 0 additions & 3 deletions source/MaaFramework/Task/PipelineTask.h
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,6 @@ class PipelineTask : public TaskBase

private:
NodeDetail run_reco_and_action(const PipelineData::NextList& list, const PipelineData& pretask);

private:
bool need_to_stop_ = false;
};

MAA_TASK_NS_END
Loading