From ce0c759dedbdb15bfb96607022fad47a7cd42d0b Mon Sep 17 00:00:00 2001 From: Ian Chua Date: Tue, 22 Sep 2026 16:06:18 +0800 Subject: [PATCH] fix: snapmakerprinteragent use moonraker's lifecycle-owned command worker --- src/slic3r/Utils/MoonrakerPrinterAgent.hpp | 5 ++++- src/slic3r/Utils/SnapmakerPrinterAgent.cpp | 4 ++-- 2 files changed, 6 insertions(+), 3 deletions(-) diff --git a/src/slic3r/Utils/MoonrakerPrinterAgent.hpp b/src/slic3r/Utils/MoonrakerPrinterAgent.hpp index 0fc1959999..ab9f2dcb94 100644 --- a/src/slic3r/Utils/MoonrakerPrinterAgent.hpp +++ b/src/slic3r/Utils/MoonrakerPrinterAgent.hpp @@ -136,6 +136,10 @@ protected: virtual void on_status_loop_tick(const std::string& dev_id) {} + // Queue work that may use agent state. The command worker is joined during + // destruction, so queued commands cannot outlive the agent. + void enqueue_command(std::function fn); + private: int handle_request(const std::string& dev_id, const std::string& json_str); int send_version_info(const std::string& dev_id); @@ -254,7 +258,6 @@ private: std::thread connect_thread; mutable std::recursive_mutex connect_mutex; - void enqueue_command(std::function fn); void run_command_worker(); std::thread cmd_thread; std::deque> cmd_queue; diff --git a/src/slic3r/Utils/SnapmakerPrinterAgent.cpp b/src/slic3r/Utils/SnapmakerPrinterAgent.cpp index 2ae67f8140..d5bd4a7217 100644 --- a/src/slic3r/Utils/SnapmakerPrinterAgent.cpp +++ b/src/slic3r/Utils/SnapmakerPrinterAgent.cpp @@ -82,10 +82,10 @@ SnapmakerPrinterAgent::SnapmakerPrinterAgent(std::string log_dir) : MoonrakerPri void SnapmakerPrinterAgent::start_camera_monitor() { - std::thread([this] { + enqueue_command([this] { send_ws_rpc("camera.start_monitor", {{"domain", "lan"}, {"interval", 0}, {"expect_pw", false}}); - }).detach(); + }); m_camera_last_fire_ms.store(now_ms()); }