From 0f7dd9b3a44251a92664e30af74c519dce062d3d Mon Sep 17 00:00:00 2001 From: "chunmao.guo" Date: Wed, 18 Oct 2023 14:39:33 +0800 Subject: [PATCH] FIX: PrinterFileSystem: lost callback when connection not ready Change-Id: Id0f0c41e51fef8220bd6bd7fb40876840fee05ad Jira: STUDIO-4811 --- src/slic3r/GUI/Printer/PrinterFileSystem.cpp | 24 +++++++++++++------- 1 file changed, 16 insertions(+), 8 deletions(-) diff --git a/src/slic3r/GUI/Printer/PrinterFileSystem.cpp b/src/slic3r/GUI/Printer/PrinterFileSystem.cpp index adb459a95..ee6a06375 100644 --- a/src/slic3r/GUI/Printer/PrinterFileSystem.cpp +++ b/src/slic3r/GUI/Printer/PrinterFileSystem.cpp @@ -1038,8 +1038,11 @@ void PrinterFileSystem::DumpLog(void * thiz, int, tchar const *msg) boost::uint32_t PrinterFileSystem::SendRequest(int type, json const &req, callback_t2 const &callback) { if (m_session.tunnel == nullptr) { - boost::unique_lock l(m_mutex); - m_cond.notify_all(); + { + boost::unique_lock l(m_mutex); + m_cond.notify_all(); + } + callback(ERROR_PIPE, json(), nullptr); return 0; } boost::uint32_t seq = m_sequence + m_callbacks.size(); @@ -1085,23 +1088,28 @@ void PrinterFileSystem::CancelRequests(std::vector const &seqs) void PrinterFileSystem::CancelRequests2(std::vector const &seqs) { - std::deque callbacks; + std::vector> callbacks; boost::unique_lock l(m_mutex); for (auto &f : seqs) { boost::uint32_t seq = f; seq -= m_sequence; - if (size_t(seq) >= m_callbacks.size()) continue; + if (size_t(seq) >= m_callbacks.size()) + continue; auto &c = m_callbacks[seq]; - if (c == nullptr) continue; - callbacks.push_back(c); - m_callbacks[seq] = callback_t2(); + if (c == nullptr) + continue; + callbacks.emplace_back(f, c); + c = nullptr; } while (!m_callbacks.empty() && m_callbacks.front() == nullptr) { m_callbacks.pop_front(); ++m_sequence; } l.unlock(); - for (auto &c : callbacks) c(ERROR_CANCEL, json(), nullptr); + for (auto &c : callbacks) { + wxLogInfo("PrinterFileSystem::CancelRequests2: %u\n", c.first); + c.second(ERROR_CANCEL, json(), nullptr); + } } void PrinterFileSystem::RecvMessageThread()