From 922af972c70c534d630e01d9f9958dd5995f6e8e Mon Sep 17 00:00:00 2001 From: Noisyfox Date: Tue, 7 Jul 2026 17:29:10 +0800 Subject: [PATCH] refactor: convert m_fila_system from raw pointer to shared_ptr Matches BambuStudio commit c8f70c6ca. DevFilaSystem* m_fila_system becomes std::shared_ptr, enabling proper shared ownership for the AMS drying control feature without no-op deleter hacks. - DeviceManager.hpp: m_fila_system and GetFilaSystem() use shared_ptr - DeviceManager.cpp: std::make_shared allocation, remove manual delete, add .get() to ParseV1_0 calls - MoonrakerPrinterAgent.cpp: add .get() to GetFilaSystem() in ParseV1_0 --- src/slic3r/GUI/DeviceManager.cpp | 6 ++---- src/slic3r/GUI/DeviceManager.hpp | 4 ++-- src/slic3r/Utils/MoonrakerPrinterAgent.cpp | 2 +- 3 files changed, 5 insertions(+), 7 deletions(-) diff --git a/src/slic3r/GUI/DeviceManager.cpp b/src/slic3r/GUI/DeviceManager.cpp index 2562d73b22..f8d7c970b2 100644 --- a/src/slic3r/GUI/DeviceManager.cpp +++ b/src/slic3r/GUI/DeviceManager.cpp @@ -566,7 +566,7 @@ MachineObject::MachineObject(DeviceManager* manager, NetworkAgent* agent, std::s m_extder_system = new DevExtderSystem(this); m_extension_tool = DevExtensionTool::Create(this); m_nozzle_system = new DevNozzleSystem(this); - m_fila_system = new DevFilaSystem(this); + m_fila_system = std::make_shared(this); m_hms_system = new DevHMS(this); m_config = new DevConfig(this); @@ -612,8 +612,6 @@ MachineObject::~MachineObject() delete m_ctrl; m_ctrl = nullptr; - delete m_fila_system; - m_fila_system = nullptr; delete m_hms_system; m_hms_system = nullptr; @@ -3723,7 +3721,7 @@ int MachineObject::parse_json(std::string tunnel, std::string payload, bool key_ update_printer_preset_name(); update_filament_list(); if (jj.contains("ams")) { - DevFilaSystemParser::ParseV1_0(jj, this, m_fila_system, key_field_only); + DevFilaSystemParser::ParseV1_0(jj, this, m_fila_system.get(), key_field_only); } /* vitrual tray*/ diff --git a/src/slic3r/GUI/DeviceManager.hpp b/src/slic3r/GUI/DeviceManager.hpp index a0d8f97ea6..fae8d60415 100644 --- a/src/slic3r/GUI/DeviceManager.hpp +++ b/src/slic3r/GUI/DeviceManager.hpp @@ -114,7 +114,7 @@ private: std::shared_ptr m_extension_tool; DevExtderSystem* m_extder_system; DevNozzleSystem* m_nozzle_system; - DevFilaSystem* m_fila_system; + std::shared_ptr m_fila_system; DevFan* m_fan; DevBed * m_bed; DevStorage* m_storage; @@ -329,7 +329,7 @@ public: DevNozzleSystem* GetNozzleSystem() const { return m_nozzle_system;} - DevFilaSystem* GetFilaSystem() const { return m_fila_system;} + std::shared_ptr GetFilaSystem() const { return m_fila_system;} bool HasAms() const; DevLamp* GetLamp() const { return m_lamp; } diff --git a/src/slic3r/Utils/MoonrakerPrinterAgent.cpp b/src/slic3r/Utils/MoonrakerPrinterAgent.cpp index f1d892134b..b0ea653dd3 100644 --- a/src/slic3r/Utils/MoonrakerPrinterAgent.cpp +++ b/src/slic3r/Utils/MoonrakerPrinterAgent.cpp @@ -536,7 +536,7 @@ void MoonrakerPrinterAgent::build_ams_payload(int ams_count, int max_lane_index, print_json["ams"] = ams_json; // Call the parser to populate DevFilaSystem - DevFilaSystemParser::ParseV1_0(print_json, obj, obj->GetFilaSystem(), false); + DevFilaSystemParser::ParseV1_0(print_json, obj, obj->GetFilaSystem().get(), false); BOOST_LOG_TRIVIAL(info) << "MoonrakerPrinterAgent::build_ams_payload: Parsed " << trays.size() << " trays"; // Set printer_type so update_sync_status() can match it against the preset's printer type.