From a8a597c6d5084d4c749ea2a4e44025d69a304b5a Mon Sep 17 00:00:00 2001 From: Alexander Vander Kelen Date: Sat, 21 Nov 2026 13:01:33 -0600 Subject: [PATCH] Fix LAN Bambu printer losing its connection when the cloud server connects (#17769) The server-connected handler selects the agent's current machine again every time the cloud server connects. For a LAN printer this makes the Bambu network plug-in unsubscribe the device, which drops the LAN session that selecting the printer opened. A connect still in flight fails with "called UnSubscribeDevice". One that already succeeded stays down with no connect result, so the printer shows as connected while every command fails with -4 and Print fails with -4030. Since #17086, OrcaSlicer connects the last LAN Bambu printer at startup, so a LAN user hits this on most starts. A cloud reconnect later in a session drops the session the same way. The selection is a cloud subscription, so a LAN printer does not need it. Move the re-select into DeviceManager::reselect_cloud_machine(), which skips a LAN-mode printer and behaves as before for any other machine. Fixes #17766 --- src/slic3r/GUI/DeviceCore/DevManager.cpp | 17 +++++++++ src/slic3r/GUI/DeviceCore/DevManager.h | 3 ++ src/slic3r/GUI/GUI_App.cpp | 6 ++- .../test_device_manager_integration.cpp | 38 +++++++++++++++++++ 4 files changed, 62 insertions(+), 2 deletions(-) diff --git a/src/slic3r/GUI/DeviceCore/DevManager.cpp b/src/slic3r/GUI/DeviceCore/DevManager.cpp index be59142997..52e238fd1a 100644 --- a/src/slic3r/GUI/DeviceCore/DevManager.cpp +++ b/src/slic3r/GUI/DeviceCore/DevManager.cpp @@ -865,6 +865,23 @@ namespace Slic3r m_agent->add_subscribe(subscribe_list_cache); } + void DeviceManager::reselect_cloud_machine() + { + if (!m_agent) + return; + + // The selection is a cloud subscription, and a LAN printer has none. Selecting one makes the + // Bambu network plugin unsubscribe the device, which drops the LAN session that connected it: + // a connect still in flight fails, and one that already succeeded stays down with no connect + // result to say so. + const std::string dev_id = m_agent->get_user_selected_machine(); + const MachineObject* obj = get_my_machine(dev_id); + if (obj && obj->is_lan_mode_printer()) + return; + + m_agent->set_user_selected_machine(dev_id); + } + std::map DeviceManager::get_my_machine_list(const std::string& agent_id) { std::map result; diff --git a/src/slic3r/GUI/DeviceCore/DevManager.h b/src/slic3r/GUI/DeviceCore/DevManager.h index 820c594685..0f30568d16 100644 --- a/src/slic3r/GUI/DeviceCore/DevManager.h +++ b/src/slic3r/GUI/DeviceCore/DevManager.h @@ -104,6 +104,9 @@ public: void add_user_subscribe(); void del_user_subscribe(); void subscribe_device_list(std::vector dev_list); + // Selects the agent's selected machine again, which subscribes a cloud printer once the cloud + // server has connected. A LAN printer is left as it is. + void reselect_cloud_machine(); /* my machine*/ MachineObject* get_my_machine(std::string dev_id); diff --git a/src/slic3r/GUI/GUI_App.cpp b/src/slic3r/GUI/GUI_App.cpp index 46cf29cc39..3257f9bbaa 100644 --- a/src/slic3r/GUI/GUI_App.cpp +++ b/src/slic3r/GUI/GUI_App.cpp @@ -2341,12 +2341,14 @@ void GUI_App::init_networking_callbacks() if (provider != this->get_printer_cloud_provider()) { return; } - m_agent->set_user_selected_machine(m_agent->get_user_selected_machine()); + if (m_device_manager) + m_device_manager->reselect_cloud_machine(); if (this->is_enable_multi_machine()) { auto evt = new wxCommandEvent(EVT_UPDATE_MACHINE_LIST); wxQueueEvent(this, evt); } - m_agent->set_user_selected_machine(m_agent->get_user_selected_machine()); + if (m_device_manager) + m_device_manager->reselect_cloud_machine(); if (m_agent->is_user_login(provider)) { /*disconnect lan*/ diff --git a/tests/slic3rutils/test_device_manager_integration.cpp b/tests/slic3rutils/test_device_manager_integration.cpp index 2994ca6793..d64b141317 100644 --- a/tests/slic3rutils/test_device_manager_integration.cpp +++ b/tests/slic3rutils/test_device_manager_integration.cpp @@ -70,9 +70,16 @@ public: return 0; } + int set_user_selected_machine(std::string dev_id) override + { + ++selections; + return OrcaPrinterAgent::set_user_selected_machine(std::move(dev_id)); + } + std::string published_device; json published_message; std::string connected_ca_file; + int selections{0}; private: AgentInfo m_info; @@ -277,6 +284,37 @@ TEST_CASE("Logging out cancels a pending last-machine restore", "[DeviceManager] CHECK_FALSE(manager.has_pending_last_machine_restore()); } +TEST_CASE("A cloud server connection selects a cloud printer again but leaves a LAN printer alone", "[DeviceManager][integration]") +{ + ScopedAppConfig app_config; + auto agent = std::make_shared("integration-agent"); + NetworkAgent network(nullptr, agent); + network.set_printer_agent(agent); + DeviceManager manager(&network, false, &app_config.config); + + BBLocalMachine machine; + machine.dev_id = "integration-lan-device"; + machine.dev_name = "Integration LAN device"; + machine.dev_ip = "192.0.2.10"; + machine.printer_type = "C11"; + REQUIRE(manager.insert_local_device(machine, "lan", "free", "", "access-code") != nullptr); + manager.parse_user_print_info(machine_list_response(ORCA_CLOUD_PROVIDER, "integration-agent", + network.get_user_machine_list_generation(), "Cloud printer")); + REQUIRE(manager.get_user_machinelist().count("integration-device") == 1); + + // The agent names the LAN printer once it is connected, as the Bambu network plugin does. + agent->set_user_selected_machine(machine.dev_id); + agent->selections = 0; + manager.reselect_cloud_machine(); + CHECK(agent->selections == 0); + + agent->set_user_selected_machine("integration-device"); + agent->selections = 0; + manager.reselect_cloud_machine(); + CHECK(agent->selections == 1); + CHECK(agent->get_user_selected_machine() == "integration-device"); +} + TEST_CASE("A CA file stays with the agent that saved it when a device is rebound", "[DeviceManager][integration]") { ScopedAppConfig app_config;