diff --git a/src/libslic3r/Format/bbs_3mf.cpp b/src/libslic3r/Format/bbs_3mf.cpp index 6a29d8196..b5225f672 100644 --- a/src/libslic3r/Format/bbs_3mf.cpp +++ b/src/libslic3r/Format/bbs_3mf.cpp @@ -6024,8 +6024,10 @@ private: boost::posix_time::ptime start; }; private: - _BBS_Backup_Manager() : m_thread(boost::ref(*this)) { + _BBS_Backup_Manager() { m_next_backup = boost::get_system_time() + boost::posix_time::seconds(m_interval); + boost::unique_lock lock(m_mutex); + m_thread = std::move(boost::thread(boost::ref(*this))); } ~_BBS_Backup_Manager() { diff --git a/src/slic3r/GUI/MediaFilePanel.cpp b/src/slic3r/GUI/MediaFilePanel.cpp index e6aef6535..1885d3f6b 100644 --- a/src/slic3r/GUI/MediaFilePanel.cpp +++ b/src/slic3r/GUI/MediaFilePanel.cpp @@ -220,6 +220,7 @@ void MediaFilePanel::SetMachineObject(MachineObject* obj) m_image_grid->SetStatus(m_bmp_failed.bmp(), _L("Not supported.")); } else { boost::shared_ptr fs(new PrinterFileSystem); + fs->Attached(); m_image_grid->SetFileType(m_last_type); m_image_grid->SetFileSystem(fs); fs->Bind(EVT_MODE_CHANGED, &MediaFilePanel::modeChanged, this); diff --git a/src/slic3r/GUI/Monitor.cpp b/src/slic3r/GUI/Monitor.cpp index 245ca07bd..6b030290d 100644 --- a/src/slic3r/GUI/Monitor.cpp +++ b/src/slic3r/GUI/Monitor.cpp @@ -227,11 +227,6 @@ void MonitorPanel::set_default() /* reset side tool*/ //m_bitmap_wifi_signal->SetBitmap(wxNullBitmap); -#if !BBL_RELEASE_TO_PUBLIC - /* reset time lapse panel */ - m_media_file_panel->SetMachineObject(nullptr); -#endif - wxGetApp().sidebar().load_ams_list({}); } diff --git a/src/slic3r/GUI/Printer/PrinterFileSystem.cpp b/src/slic3r/GUI/Printer/PrinterFileSystem.cpp index ecc24f03f..f14ce46c8 100644 --- a/src/slic3r/GUI/Printer/PrinterFileSystem.cpp +++ b/src/slic3r/GUI/Printer/PrinterFileSystem.cpp @@ -27,7 +27,6 @@ struct StaticBambuLib : BambuLib { PrinterFileSystem::PrinterFileSystem() : BambuLib(StaticBambuLib::get()) - , m_recv_thread(&PrinterFileSystem::RecvMessageThread, this) { if (!default_thumbnail.IsOk()) default_thumbnail = wxImage(Slic3r::encode_path(Slic3r::var("live_stream_default.png").c_str())); @@ -41,7 +40,9 @@ PrinterFileSystem::PrinterFileSystem() } PrinterFileSystem::~PrinterFileSystem() -{ m_recv_thread.detach(); } +{ + m_recv_thread.detach(); +} void PrinterFileSystem::SetFileType(FileType type) { @@ -251,6 +252,15 @@ int PrinterFileSystem::RecvData(std::function const & return result; } +void PrinterFileSystem::Attached() +{ + boost::unique_lock lock(m_mutex); + m_recv_thread = std::move(boost::thread([w = weak_from_this()] { + boost::shared_ptr s = w.lock(); + if (s) s->RecvMessageThread(); + })); +} + void PrinterFileSystem::Start() { boost::unique_lock l(m_mutex); @@ -277,8 +287,6 @@ void PrinterFileSystem::Stop(bool quit) boost::unique_lock l(m_mutex); if (quit) { m_session.owner = nullptr; - // let the thread delete this - m_callbacks.push_back([thiz = shared_from_this()](int result, json const &, unsigned char const *) { (void) thiz; }); } else if (m_stopped) { return; } @@ -624,7 +632,7 @@ void PrinterFileSystem::RecvMessageThread() if (m_stopped && (m_session.owner == nullptr || (m_messages.empty() && m_callbacks.empty()))) { Reconnect(l, 0); // Close and wait start again if (m_session.owner == nullptr) { - // clear callbacks may invoke destructor, so clear first + // clear callbacks first auto callbacks(std::move(m_callbacks)); break; } diff --git a/src/slic3r/GUI/Printer/PrinterFileSystem.h b/src/slic3r/GUI/Printer/PrinterFileSystem.h index 31df48994..eb84525de 100644 --- a/src/slic3r/GUI/Printer/PrinterFileSystem.h +++ b/src/slic3r/GUI/Printer/PrinterFileSystem.h @@ -149,6 +149,8 @@ public: Status GetStatus() const { return m_status; } int GetLastError() const { return m_last_error; } + void Attached(); + void Start(); void Retry();