From fa832b753962211b4cb4f5988a68985be96faf21 Mon Sep 17 00:00:00 2001 From: "weizhen.xie" Date: Fri, 1 Aug 2025 15:05:37 +0800 Subject: [PATCH] FIX:Fix the crashes when users import 3MF files that use third-party printers. Jira:STUDIO-13586 Change-Id: I977e9e426e2f2b98da389e7bfa8fb57388c55628 (cherry picked from commit 9d170ebd52a94579a81a9e8bc8eb19ae27ba3076) --- src/slic3r/GUI/MainFrame.cpp | 6 ++++-- src/slic3r/GUI/PhysicalPrinterDialog.cpp | 11 +++++++++++ src/slic3r/GUI/PhysicalPrinterDialog.hpp | 1 + 3 files changed, 16 insertions(+), 2 deletions(-) diff --git a/src/slic3r/GUI/MainFrame.cpp b/src/slic3r/GUI/MainFrame.cpp index b26e5fb5d1..4329b3b351 100644 --- a/src/slic3r/GUI/MainFrame.cpp +++ b/src/slic3r/GUI/MainFrame.cpp @@ -1495,8 +1495,10 @@ bool MainFrame::can_send_gcode() const if (m_plater && !m_plater->model().objects.empty()) { auto cfg = wxGetApp().preset_bundle->printers.get_edited_preset().config; - if (const auto *print_host_opt = cfg.option("print_host"); print_host_opt) - return !print_host_opt->value.empty(); + + const auto *print_host_opt = cfg.option("print_host"); + if (! print_host_opt) return false; + else return !print_host_opt->value.empty(); } return true; } diff --git a/src/slic3r/GUI/PhysicalPrinterDialog.cpp b/src/slic3r/GUI/PhysicalPrinterDialog.cpp index bbc4d9e5e4..be28425cd5 100644 --- a/src/slic3r/GUI/PhysicalPrinterDialog.cpp +++ b/src/slic3r/GUI/PhysicalPrinterDialog.cpp @@ -94,6 +94,7 @@ PhysicalPrinterDialog::PhysicalPrinterDialog(wxWindow* parent) : m_config = &wxGetApp().preset_bundle->printers.get_edited_preset().config; m_optgroup = new ConfigOptionsGroup(this, _L("Print Host upload"), m_config); + check_host_key_valid(); build_printhost_settings(m_optgroup); auto dlg_btns = new DialogButtons(this, {"OK"}); @@ -726,6 +727,16 @@ void PhysicalPrinterDialog::on_dpi_changed(const wxRect& suggested_rect) Refresh(); } +void PhysicalPrinterDialog::check_host_key_valid() +{ + std::vector keys = {"print_host", "print_host_webui", "printhost_apikey", "printhost_cafile", "printhost_user", "printhost_password", "printhost_port"}; + for (auto &key : keys) { + auto it = m_config->option(key); + if (!it) m_config->set_key_value(key, new ConfigOptionString("")); + } + return; +} + void PhysicalPrinterDialog::OnOK(wxEvent& event) { wxGetApp().get_tab(Preset::TYPE_PRINTER)->save_preset("", false, false, true, m_preset_name ); diff --git a/src/slic3r/GUI/PhysicalPrinterDialog.hpp b/src/slic3r/GUI/PhysicalPrinterDialog.hpp index cef6d8fe63..0ba2cad54f 100644 --- a/src/slic3r/GUI/PhysicalPrinterDialog.hpp +++ b/src/slic3r/GUI/PhysicalPrinterDialog.hpp @@ -69,6 +69,7 @@ public: protected: void on_dpi_changed(const wxRect& suggested_rect) override; void on_sys_color_changed() override {}; + void check_host_key_valid(); };