From cf0c5624a15fad28c4a0f88932217e7500abec58 Mon Sep 17 00:00:00 2001 From: "lane.wei" Date: Fri, 17 Jan 2025 20:23:29 +0800 Subject: [PATCH] FIX: gui: fix the crash issue when close guide frame at the beginning jira: STUDIO-9941 Change-Id: I47e189e838ae606d294d0c0b4ccffc6f833a27c3 (cherry picked from commit 093a7c25cb7507d0d6af228c2efa3410e1184c27) --- src/slic3r/GUI/WebGuideDialog.cpp | 41 ++++++++++++++++++++----------- src/slic3r/GUI/WebGuideDialog.hpp | 2 ++ 2 files changed, 29 insertions(+), 14 deletions(-) diff --git a/src/slic3r/GUI/WebGuideDialog.cpp b/src/slic3r/GUI/WebGuideDialog.cpp index ce9e3e20d9..7ec50b6b1f 100644 --- a/src/slic3r/GUI/WebGuideDialog.cpp +++ b/src/slic3r/GUI/WebGuideDialog.cpp @@ -48,7 +48,7 @@ static wxString update_custom_filaments() json m_CustomFilaments = json::array(); PresetBundle * preset_bundle = wxGetApp().preset_bundle; std::map> temp_filament_id_to_presets = preset_bundle->filaments.get_filament_presets(); - + std::vector> need_sort; bool need_delete_some_filament = false; for (std::pair> filament_id_to_presets : temp_filament_id_to_presets) { @@ -72,7 +72,7 @@ static wxString update_custom_filaments() auto filament_vendor = dynamic_cast(const_cast(preset)->config.option("filament_vendor", false)); if (filament_vendor && filament_vendor->values.size() && filament_vendor->values[0] == "Generic") not_need_show = true; } - + if (filament_name.empty()) { std::string preset_name = preset->name; size_t index_at = preset_name.find(" @"); @@ -132,7 +132,7 @@ GuideFrame::GuideFrame(GUI_App *pGUI, long style) } m_browser->Hide(); m_browser->SetSize(0, 0); - + SetSizer(topsizer); topsizer->Add(m_browser, wxSizerFlags().Expand().Proportion(1)); @@ -187,6 +187,12 @@ GuideFrame::GuideFrame(GUI_App *pGUI, long style) GuideFrame::~GuideFrame() { + m_destroy = true; + if (m_load_task && m_load_task->joinable()) { + m_load_task->join(); + delete m_load_task; + m_load_task = nullptr; + } if (m_browser) { delete m_browser; m_browser = nullptr; @@ -296,15 +302,16 @@ void GuideFrame::OnNavigationComplete(wxWebViewEvent &evt) { //wxLogMessage("%s", "Navigation complete; url='" + evt.GetURL() + "'"); if (!bFirstComplete) { - boost::thread LoadProfileThread(boost::bind(&GuideFrame::LoadProfileData, this)); - LoadProfileThread.detach(); + m_load_task = new boost::thread(boost::bind(&GuideFrame::LoadProfileData, this)); + // boost::thread LoadProfileThread(boost::bind(&GuideFrame::LoadProfileData, this)); + //LoadProfileThread.detach(); bFirstComplete = true; } m_browser->Show(); Layout(); - + wxString NewUrl = evt.GetURL(); UpdateState(); @@ -929,9 +936,9 @@ int GuideFrame::GetFilamentInfo( std::string VendorDirectory, json & pFilaList, if (jLocal.contains("inherits")) { std::string FName = jLocal["inherits"]; - if (!pFilaList.contains(FName)) { + if (!pFilaList.contains(FName)) { BOOST_LOG_TRIVIAL(info) << __FUNCTION__ << "pFilaList - Not Contains inherits filaments: " << FName; - return -1; + return -1; } std::string FPath = pFilaList[FName]["sub_path"]; @@ -1028,6 +1035,8 @@ int GuideFrame::LoadProfileData() LoadProfileFamily(w2s(strVendor), iter->path().string()); loaded_vendors.insert(w2s(strVendor)); } + if (m_destroy) + return 0; } boost::filesystem::directory_iterator others_endIter; @@ -1043,6 +1052,8 @@ int GuideFrame::LoadProfileData() LoadProfileFamily(w2s(strVendor), iter->path().string()); loaded_vendors.insert(w2s(strVendor)); } + if (m_destroy) + return 0; } //sync to web @@ -1053,12 +1064,14 @@ int GuideFrame::LoadProfileData() m_Res["command"] = "userguide_profile_load_finish"; m_Res["sequence_id"] = "10001"; wxString strJS = wxString::Format("HandleStudio(%s)", m_Res.dump(-1, ' ', true)); - wxGetApp().CallAfter([this, strJS] { RunScript(strJS); }); + if (!m_destroy) + wxGetApp().CallAfter([this, strJS] { RunScript(strJS); }); //sync to appconfig - wxGetApp().CallAfter([this] { SaveProfileData(); }); + if (!m_destroy) + wxGetApp().CallAfter([this] { SaveProfileData(); }); - } catch (std::exception &e) { + } catch (std::exception& e) { // wxLogMessage("GUIDE: load_profile_error %s ", e.what()); // wxMessageBox(e.what(), "", MB_OK); BOOST_LOG_TRIVIAL(error) << __FUNCTION__ << ", error: " << e.what() << std::endl; @@ -1281,7 +1294,7 @@ int GuideFrame::LoadProfileFamily(std::string strVendor, std::string strFilePath std::string sub_file = sub_path.string(); LoadFile(sub_file, contents); json pm = json::parse(contents); - + std::string strInstant = pm["instantiation"]; BOOST_LOG_TRIVIAL(info) << __FUNCTION__ << "Load Filament:" << s1 << ",Path:" << sub_file << ",instantiation?" << strInstant; @@ -1290,9 +1303,9 @@ int GuideFrame::LoadProfileFamily(std::string strVendor, std::string strFilePath std::string sT; int nRet = GetFilamentInfo(vendor_dir.string(),tFilaList, sub_file, sV, sT); - if (nRet != 0) { + if (nRet != 0) { BOOST_LOG_TRIVIAL(info) << __FUNCTION__ << "Load Filament:" << s1 << ",GetFilamentInfo Failed, Vendor:" << sV << ",Type:"<< sT; - continue; + continue; } OneFF["vendor"] = sV; diff --git a/src/slic3r/GUI/WebGuideDialog.hpp b/src/slic3r/GUI/WebGuideDialog.hpp index f2f75445ae..d2ab468fcc 100644 --- a/src/slic3r/GUI/WebGuideDialog.hpp +++ b/src/slic3r/GUI/WebGuideDialog.hpp @@ -110,6 +110,8 @@ private: //First Load bool bFirstComplete{false}; + bool m_destroy{false}; + boost::thread* m_load_task{ nullptr }; // User Config bool PrivacyUse;