ENH:add protection in threads

jira:[for random crash]

Change-Id: I6286012dd77abccba461f7cd72a6fc531a84c95f
This commit is contained in:
tao wang 2023-10-31 21:02:41 +08:00 committed by Lane.Wei
parent eb9cc0c9e5
commit eaa7abf518
8 changed files with 66 additions and 46 deletions

View File

@ -242,20 +242,25 @@ void SelectMObjectPopup::Popup(wxWindow* WXUNUSED(focus))
if (wxGetApp().is_user_login()) {
if (!get_print_info_thread) {
get_print_info_thread = new boost::thread(Slic3r::create_thread([&] {
get_print_info_thread = new boost::thread(Slic3r::create_thread([this, token = std::weak_ptr(m_token)] {
NetworkAgent* agent = wxGetApp().getAgent();
unsigned int http_code;
std::string body;
int result = agent->get_user_print_info(&http_code, &body);
wxGetApp().CallAfter([token, this, result, body]() {
if (token.expired()) {return;}
if (result == 0) {
m_print_info = body;
}
else {
m_print_info = "";
}
wxCommandEvent event(EVT_UPDATE_USER_MLIST);
event.SetEventObject(this);
wxPostEvent(this, event);
});
}));
}
}

View File

@ -89,6 +89,7 @@ private:
std::vector<MPanel*> m_user_list_machine_panel;
boost::thread* get_print_info_thread{ nullptr };
std::string m_print_info;
std::shared_ptr<int> m_token = std::make_shared<int>(0);
std::map<std::string, MachineObject*> m_bind_machine_list;
private:

View File

@ -1255,7 +1255,7 @@ InputIpAddressDialog::InputIpAddressDialog(wxWindow* parent)
m_sizer_body->Add(m_trouble_shoot, 0, wxLEFT | wxRIGHT | wxEXPAND, FromDIP(40));
m_sizer_body->Add(0, 0, 0, wxTOP, FromDIP(8));
m_sizer_body->Add(m_sizer_button, 0, wxRIGHT | wxEXPAND, FromDIP(18));
m_sizer_body->Add(m_sizer_button, 0, wxRIGHT | wxEXPAND, FromDIP(25));
m_sizer_body->Layout();
SetSizer(m_sizer_body);

View File

@ -429,19 +429,23 @@ void SelectMachinePopup::Popup(wxWindow *WXUNUSED(focus))
if (wxGetApp().is_user_login()) {
if (!get_print_info_thread) {
get_print_info_thread = new boost::thread(Slic3r::create_thread([&] {
get_print_info_thread = new boost::thread(Slic3r::create_thread([this, token = std::weak_ptr(m_token)] {
NetworkAgent* agent = wxGetApp().getAgent();
unsigned int http_code;
std::string body;
int result = agent->get_user_print_info(&http_code, &body);
CallAfter([token, this, result, body]() {
if (token.expired()) {return;}
if (result == 0) {
m_print_info = body;
} else {
}
else {
m_print_info = "";
}
wxCommandEvent event(EVT_UPDATE_USER_MACHINE_LIST);
event.SetEventObject(this);
wxPostEvent(this, event);
});
}));
}
}
@ -2828,11 +2832,13 @@ void SelectMachineDialog::update_user_machine_list()
{
NetworkAgent* m_agent = wxGetApp().getAgent();
if (m_agent && m_agent->is_user_login()) {
boost::thread get_print_info_thread = Slic3r::create_thread([&] {
boost::thread get_print_info_thread = Slic3r::create_thread([this, token = std::weak_ptr(m_token)] {
NetworkAgent* agent = wxGetApp().getAgent();
unsigned int http_code;
std::string body;
int result = agent->get_user_print_info(&http_code, &body);
CallAfter([token, this, result, body] {
if (token.expired()) {return;}
if (result == 0) {
m_print_info = body;
}
@ -2843,6 +2849,7 @@ void SelectMachineDialog::update_user_machine_list()
event.SetEventObject(this);
wxPostEvent(this, event);
});
});
} else {
wxCommandEvent event(EVT_UPDATE_USER_MACHINE_LIST);
event.SetEventObject(this);

View File

@ -215,7 +215,8 @@ private:
std::vector<MachinePanel*> m_user_list_machine_panel;
std::vector<MachinePanel*> m_other_list_machine_panel;
boost::thread* get_print_info_thread{ nullptr };
std::string m_print_info;
std::shared_ptr<int> m_token = std::make_shared<int>(0);
std::string m_print_info = "";
bool m_dismiss { false };
std::map<std::string, MachineObject*> m_bind_machine_list;
@ -304,6 +305,7 @@ private:
wxColour m_colour_bold_color{wxColour(38, 46, 48)};
StateColor m_btn_bg_enable;
std::shared_ptr<int> m_token = std::make_shared<int>(0);
std::map<std::string, CheckBox *> m_checkbox_list;
//std::map<std::string, bool> m_checkbox_state_list;
std::vector<wxString> m_bedtype_list;

View File

@ -824,11 +824,13 @@ void SendToPrinterDialog::update_user_machine_list()
{
NetworkAgent* m_agent = wxGetApp().getAgent();
if (m_agent && m_agent->is_user_login()) {
boost::thread get_print_info_thread = Slic3r::create_thread([&] {
boost::thread get_print_info_thread = Slic3r::create_thread([this, token = std::weak_ptr(m_token)] {
NetworkAgent* agent = wxGetApp().getAgent();
unsigned int http_code;
std::string body;
int result = agent->get_user_print_info(&http_code, &body);
CallAfter([token, this, result, body] {
if (token.expired()) {return;}
if (result == 0) {
m_print_info = body;
}
@ -839,6 +841,7 @@ void SendToPrinterDialog::update_user_machine_list()
event.SetEventObject(this);
wxPostEvent(this, event);
});
});
} else {
wxCommandEvent event(EVT_UPDATE_USER_MACHINE_LIST);
event.SetEventObject(this);

View File

@ -114,7 +114,7 @@ private:
wxTimer* m_refresh_timer{ nullptr };
std::shared_ptr<BBLStatusBarSend> m_status_bar;
wxScrolledWindow* m_sw_print_failed_info{nullptr};
std::shared_ptr<int> m_token = std::make_shared<int>(0);
public:
SendToPrinterDialog(Plater* plater = nullptr);

View File

@ -2733,9 +2733,11 @@ void StatusPanel::update_basic_print_data(bool def)
void StatusPanel::update_model_info()
{
auto get_subtask_fn = [this](BBLModelTask* subtask) {
CallAfter([this, subtask]() {
if (obj && obj->subtask_id_ == subtask->task_id) {
obj->set_modeltask(subtask);
}
});
};