FIX: add protection for get_model_task_thread thread

Jira: XXXX

Change-Id: I3cbc17d181a0e13c658f31eaeb6a4df878e6df41
Signed-off-by: maosheng.wei <maosheng.wei@bambulab.com>
This commit is contained in:
maosheng.wei 2023-11-01 14:41:41 +08:00 committed by Lane.Wei
parent eaa7abf518
commit 5b5e5be07c
2 changed files with 14 additions and 3 deletions

View File

@ -4609,7 +4609,8 @@ void MachineObject::update_model_task()
delete rating_info;
rating_info = nullptr;
}
get_model_task_thread = new boost::thread([this, curr_instance_id]{
get_model_task_thread = new boost::thread([this, curr_instance_id, token = std::weak_ptr<int>(m_token)]{
if (token.expired()) { return; }
try {
std::string rating_result;
unsigned int http_code = 404;
@ -4618,7 +4619,7 @@ void MachineObject::update_model_task()
res = m_agent->get_model_mall_rating_result(curr_instance_id, rating_result, http_code, http_error);
request_model_result++;
BOOST_LOG_TRIVIAL(info) << "request times: " << request_model_result << " http code: " << http_code;
rating_info = new RatingInfo();
auto rating_info = new RatingInfo();
rating_info->http_code = http_code;
if (0 == res && 200 == http_code) {
try {
@ -4632,6 +4633,9 @@ void MachineObject::update_model_task()
} else {
rating_info->request_successful = false;
BOOST_LOG_TRIVIAL(info) << "can not get rating id";
Slic3r::GUI::wxGetApp().CallAfter([this, token, rating_info]() {
if (!token.expired()) this->rating_info = rating_info;
});
return;
}
if (rating_json.contains("score")) {
@ -4644,12 +4648,18 @@ void MachineObject::update_model_task()
if (rating_json.contains("images")) {
rating_info->image_url_paths = rating_json["images"].get<std::vector<std::string>>();
}
Slic3r::GUI::wxGetApp().CallAfter([this, token, rating_info]() {
if (!token.expired()) this->rating_info = rating_info;
});
} catch (...) {
BOOST_LOG_TRIVIAL(info) << "parse model mall result json failed";
}
}
else {
rating_info->request_successful = false;
Slic3r::GUI::wxGetApp().CallAfter([this, token, rating_info]() {
if (!token.expired()) this->rating_info = rating_info;
});
BOOST_LOG_TRIVIAL(info) << "model mall result request failed, request time: " << request_model_result << " http_code: " << http_code
<< " error msg: " << http_error;
return;

View File

@ -312,7 +312,8 @@ struct DisValue {
class MachineObject
{
private:
NetworkAgent* m_agent { nullptr };
NetworkAgent * m_agent{nullptr};
std::shared_ptr<int> m_token = std::shared_ptr<int>(0);
bool check_valid_ip();
void _parse_print_option_ack(int option);