From 57b3a040e2a16178077f0b44bddf615a541cd599 Mon Sep 17 00:00:00 2001 From: Hanif Koh Date: Tue, 22 Sep 2026 14:55:18 +0800 Subject: [PATCH] Pass bind_detect's Result to Python by Reference pybind11 copies a reference argument to an override, so a Python printer agent that filled in detect wrote to a throwaway object and the host always saw an empty detectResult. Pass it as a pointer so Python edits the caller's struct. --- .../PrinterAgentPluginCapabilityTrampoline.hpp | 3 ++- tests/slic3rutils/test_plugin_printer_agent.cpp | 10 ++++++++-- 2 files changed, 10 insertions(+), 3 deletions(-) diff --git a/src/slic3r/plugin/pluginTypes/printerAgent/PrinterAgentPluginCapabilityTrampoline.hpp b/src/slic3r/plugin/pluginTypes/printerAgent/PrinterAgentPluginCapabilityTrampoline.hpp index 6331ee64a6..cdb533d2cb 100644 --- a/src/slic3r/plugin/pluginTypes/printerAgent/PrinterAgentPluginCapabilityTrampoline.hpp +++ b/src/slic3r/plugin/pluginTypes/printerAgent/PrinterAgentPluginCapabilityTrampoline.hpp @@ -69,7 +69,8 @@ public: int bind_detect(std::string dev_ip, std::string sec_link, detectResult& detect) override { - ORCA_PY_AGENT_OVERRIDE(int, bind_detect, dev_ip, sec_link, detect); + // Passed as a pointer: pybind11 copies a reference argument, so the plugin's writes would be lost. + ORCA_PY_AGENT_OVERRIDE(int, bind_detect, dev_ip, sec_link, &detect); } std::string get_user_selected_machine() override diff --git a/tests/slic3rutils/test_plugin_printer_agent.cpp b/tests/slic3rutils/test_plugin_printer_agent.cpp index b6e5f4a36e..2065360080 100644 --- a/tests/slic3rutils/test_plugin_printer_agent.cpp +++ b/tests/slic3rutils/test_plugin_printer_agent.cpp @@ -140,10 +140,14 @@ TEST_CASE("A working printer agent's answers reach the host unchanged", "[Plugin " def start_discovery(self, start, sending): return start and not sending\n" " def get_user_selected_machine(self): return 'machine'\n" " def get_filament_sync_mode(self): return orca.printer_agent.FilamentSyncMode.Pull\n" - " def request_bind_ticket(self): return (3, 'ticket')\n"); + " def request_bind_ticket(self): return (3, 'ticket')\n" + " def bind_detect(self, dev_ip, sec_link, detect):\n" + " detect.dev_id = dev_ip\n" + " return 0\n"); REQUIRE(agent.agent); - std::string ticket; + std::string ticket; + detectResult detect; CHECK(agent->get_agent_info().id == "id"); CHECK(agent->disconnect_printer() == 7); @@ -152,4 +156,6 @@ TEST_CASE("A working printer agent's answers reach the host unchanged", "[Plugin CHECK(agent->get_filament_sync_mode() == FilamentSyncMode::pull); CHECK(agent->request_bind_ticket(&ticket) == 3); CHECK(ticket == "ticket"); + CHECK(agent->bind_detect("192.168.0.2", "secure", detect) == 0); + CHECK(detect.dev_id == "192.168.0.2"); }