Skip to content

Commit 62afa12

Browse files
authored
fix: fix StopTask not work (#500)
1 parent 0bf1c41 commit 62afa12

File tree

5 files changed

+25
-10
lines changed

5 files changed

+25
-10
lines changed

source/MaaFramework/Task/Component/Actuator.cpp

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,9 @@ bool Actuator::run(const cv::Rect& reco_hit, MaaRecoId reco_id, const PipelineDa
6161
break;
6262
case Type::StopTask:
6363
LogInfo << "Action: StopTask";
64-
return false;
64+
context_.need_to_stop() = true;
65+
ret = true;
66+
break;
6567
default:
6668
ret = false;
6769
LogError << "Unknown action" << VAR(static_cast<int>(pipeline_data.action_type));

source/MaaFramework/Task/Context.cpp

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -203,6 +203,11 @@ std::optional<Context::PipelineData> Context::get_pipeline_data(const std::strin
203203
return std::nullopt;
204204
}
205205

206+
bool& Context::need_to_stop()
207+
{
208+
return need_to_stop_;
209+
}
210+
206211
bool Context::check_pipeline() const
207212
{
208213
if (!tasker_) {

source/MaaFramework/Task/Context.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,7 @@ class Context
5050

5151
public:
5252
std::optional<PipelineData> get_pipeline_data(const std::string& task_name);
53+
bool& need_to_stop();
5354

5455
private:
5556
bool check_pipeline() const;
@@ -60,6 +61,8 @@ class Context
6061
PipelineDataMap pipeline_override_;
6162

6263
private:
64+
bool need_to_stop_ = false;
65+
6366
mutable std::vector<std::shared_ptr<Context>> clone_holder_;
6467
};
6568

source/MaaFramework/Task/PipelineTask.cpp

Lines changed: 14 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ bool PipelineTask::run()
3535
PipelineData::NextList interrupt;
3636
bool error_handling = false;
3737

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

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

4545
auto node_detail = run_reco_and_action(list, current);
4646

47-
if (need_to_stop_) {
48-
LogError << "need_to_stop" << VAR(current.name);
47+
if (context_->need_to_stop()) {
48+
LogWarn << "need_to_stop" << VAR(current.name);
4949
return true;
5050
}
5151

@@ -105,14 +105,22 @@ bool PipelineTask::run()
105105

106106
void PipelineTask::post_stop()
107107
{
108-
need_to_stop_ = true;
108+
if (!context_) {
109+
LogError << "context is null";
110+
return;
111+
}
112+
context_->need_to_stop() = true;
109113
}
110114

111115
NodeDetail PipelineTask::run_reco_and_action(const PipelineData::NextList& list, const PipelineData& pretask)
112116
{
113117
if (!tasker_) {
114118
LogError << "tasker is null";
115119
return {};
120+
}
121+
if (!context_) {
122+
LogError << "context is null";
123+
return {};
116124
}
117125

118126
RecoResult reco;
@@ -129,8 +137,8 @@ NodeDetail PipelineTask::run_reco_and_action(const PipelineData::NextList& list,
129137
break;
130138
}
131139

132-
if (need_to_stop_) {
133-
LogError << "need_to_stop" << VAR(pretask.name);
140+
if (context_->need_to_stop()) {
141+
LogWarn << "need_to_stop" << VAR(pretask.name);
134142
return {};
135143
}
136144

source/MaaFramework/Task/PipelineTask.h

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -19,9 +19,6 @@ class PipelineTask : public TaskBase
1919

2020
private:
2121
NodeDetail run_reco_and_action(const PipelineData::NextList& list, const PipelineData& pretask);
22-
23-
private:
24-
bool need_to_stop_ = false;
2522
};
2623

2724
MAA_TASK_NS_END

0 commit comments

Comments
 (0)