From 89c83fb8a62177a80cb53a0abec4b4188d4edf0e Mon Sep 17 00:00:00 2001 From: Stone Li Date: Thu, 1 Sep 2022 10:54:11 +0800 Subject: [PATCH] FIX: fix crash when to press cancel button it would crash when avatar of user is loading. cancel web request before closing dialog. Change-Id: Ib41c5d8e7b5663d15c7d7f544335b48f47c25fea Signed-off-by: Stone Li --- src/slic3r/GUI/BindDialog.cpp | 22 ++++++++++++++-------- src/slic3r/GUI/BindDialog.hpp | 3 +++ 2 files changed, 17 insertions(+), 8 deletions(-) diff --git a/src/slic3r/GUI/BindDialog.cpp b/src/slic3r/GUI/BindDialog.cpp index 3820a2c47..1b43b5dc9 100644 --- a/src/slic3r/GUI/BindDialog.cpp +++ b/src/slic3r/GUI/BindDialog.cpp @@ -92,12 +92,12 @@ namespace GUI { m_avatar = new wxStaticBitmap(m_panel_right, wxID_ANY, wxNullBitmap, wxDefaultPosition, wxSize(FromDIP(60), FromDIP(60)), 0); - wxWebRequest request = wxWebSession::GetDefault().CreateRequest(this, wxGetApp().getAgent()->get_user_avatar()); - if (!request.IsOk()) { + web_request = wxWebSession::GetDefault().CreateRequest(this, wxGetApp().getAgent()->get_user_avatar()); + if (!web_request.IsOk()) { // todo request fail } // Start the request - request.Start(); + web_request.Start(); } m_sizer_right_v->Add(m_avatar, 0, wxALIGN_CENTER, 0); @@ -209,19 +209,25 @@ namespace GUI { void BindMachineDialog::on_cancel(wxCommandEvent &event) { - if (m_bind_job) { - m_bind_job->cancel(); - m_bind_job->join(); - } + on_destroy(); EndModal(wxID_CANCEL); } - void BindMachineDialog::on_close(wxCloseEvent &event) + void BindMachineDialog::on_destroy() { if (m_bind_job) { m_bind_job->cancel(); m_bind_job->join(); } + + if (web_request.IsOk()) { + web_request.Cancel(); + } + } + + void BindMachineDialog::on_close(wxCloseEvent &event) + { + on_destroy(); event.Skip(); } diff --git a/src/slic3r/GUI/BindDialog.hpp b/src/slic3r/GUI/BindDialog.hpp index 803bb1535..f7ed5debf 100644 --- a/src/slic3r/GUI/BindDialog.hpp +++ b/src/slic3r/GUI/BindDialog.hpp @@ -16,6 +16,7 @@ #include #include #include +#include #include "wxExtensions.hpp" #include "Plater.hpp" #include "Widgets/StepCtrl.hpp" @@ -54,6 +55,7 @@ private: Button * m_button_cancel; wxSimplebook *m_simplebook; wxStaticBitmap *m_avatar; + wxWebRequest web_request; MachineObject * m_machine_info{nullptr}; std::shared_ptr m_bind_job; @@ -71,6 +73,7 @@ public: void update_machine_info(MachineObject *info) { m_machine_info = info; }; void on_show(wxShowEvent &event); void on_close(wxCloseEvent& event); + void on_destroy(); }; class UnBindMachineDialog : public DPIDialog