From 2e41c8aafeae35049209cc11796e8d6f37449e5b Mon Sep 17 00:00:00 2001 From: Filip Sykala Date: Tue, 23 Nov 2021 13:13:12 +0100 Subject: [PATCH] remove thread --- src/slic3r/GUI/Jobs/EmbossJob.cpp | 34 ++++++++++++++++++++++--------- src/slic3r/GUI/Jobs/EmbossJob.hpp | 1 - 2 files changed, 24 insertions(+), 11 deletions(-) diff --git a/src/slic3r/GUI/Jobs/EmbossJob.cpp b/src/slic3r/GUI/Jobs/EmbossJob.cpp index 984f2d7c5..2795ace4c 100644 --- a/src/slic3r/GUI/Jobs/EmbossJob.cpp +++ b/src/slic3r/GUI/Jobs/EmbossJob.cpp @@ -24,19 +24,33 @@ EmbossJob::~EmbossJob() { void EmbossJob::restart(const Data &data) { if (Job::is_running()) { + Job::cancel(); std::lock_guard lk(m_mutex); bool create_restart = !m_data_next.has_value(); - m_data_next = data; // copy - if (create_restart) { - if (m_restart_thread.joinable()) m_restart_thread.join(); - m_restart_thread = std::thread([this]() { - Job::cancel(); - Job::join(); - std::lock_guard lk(m_mutex); - m_data = std::move(m_data_next); + m_data_next = data; // copy - // after move optional, data is UNDEFINED - m_data_next = {}; + if (create_restart) { + wxGetApp().plater()->CallAfter([this]() { + const Plater *plater = wxGetApp().plater(); + if (plater == nullptr) return; + const GLCanvas3D *canvas = plater->canvas3D(); + if (canvas == nullptr) return; + const GLGizmosManager &mng = canvas->get_gizmos_manager(); + // check if simplify is still activ gizmo + if (mng.get_current_type() != GLGizmosManager::Emboss) return; + + // when emboss is current, this object exist + Job::join(); + { + // Not neccessary to lock mutex because job is stoped, + // but for sure that no other thread try to restart job. + // Is not critical and could be there. + std::lock_guard lk(m_mutex); + assert(m_data_next.has_value()); + m_data = std::move(m_data_next); + // after move optional, data is UNDEFINED + m_data_next = {}; + } Job::start(); }); } diff --git a/src/slic3r/GUI/Jobs/EmbossJob.hpp b/src/slic3r/GUI/Jobs/EmbossJob.hpp index c88f710cb..490bd9d9e 100644 --- a/src/slic3r/GUI/Jobs/EmbossJob.hpp +++ b/src/slic3r/GUI/Jobs/EmbossJob.hpp @@ -59,7 +59,6 @@ private: std::mutex m_mutex; // protect next data std::optional m_data_next; - std::thread m_restart_thread; // TODO: move to objec list utils void select_volume(ModelVolume * volume);