mirror of
https://github.com/OrcaSlicer/OrcaSlicer.git
synced 2026-10-13 19:01:21 +00:00
Fix multi-device task list using a deleted network agent after plug-in reload
This commit is contained in:
@@ -4020,6 +4020,11 @@ bool GUI_App::on_init_network(bool try_backup)
|
||||
else
|
||||
m_user_manager->set_agent(m_agent);
|
||||
|
||||
// A hot reload deletes the agent the task manager was built with. It lives until restart, so repoint it
|
||||
// even if multi-device has since been turned off.
|
||||
if (m_task_manager)
|
||||
m_task_manager->set_agent(m_agent);
|
||||
|
||||
if (this->is_enable_multi_machine()) {
|
||||
if (!m_task_manager) {
|
||||
m_task_manager = new Slic3r::TaskManager(m_agent);
|
||||
|
||||
@@ -171,6 +171,11 @@ TaskManager::TaskManager(NetworkAgent* agent)
|
||||
;
|
||||
}
|
||||
|
||||
void TaskManager::set_agent(NetworkAgent* agent)
|
||||
{
|
||||
m_agent = agent;
|
||||
}
|
||||
|
||||
|
||||
int TaskManager::start_print(const std::vector<PrintParams>& params, TaskSettings* settings)
|
||||
{
|
||||
@@ -240,17 +245,18 @@ int TaskManager::schedule(TaskStateInfo* task)
|
||||
fire_lifecycle_event(LifecycleEvent::PrintJobStarted, start_ctx);
|
||||
|
||||
int result = -1;
|
||||
if (!m_agent) {
|
||||
NetworkAgent* agent = m_agent;
|
||||
if (!agent) {
|
||||
BOOST_LOG_TRIVIAL(trace) << "task_manager: NetworkAgent is nullptr";
|
||||
}
|
||||
else {
|
||||
assert(m_agent);
|
||||
assert(agent);
|
||||
try {
|
||||
// DEBUG FOR TEST
|
||||
#if 0
|
||||
result = start_print_test(task->get_params(), task->update_status_fn, task->cancel_fn, task->wait_fn);
|
||||
#else
|
||||
result = m_agent->start_print(task->get_params(), task->update_status_fn, task->cancel_fn, task->wait_fn);
|
||||
result = agent->start_print(task->get_params(), task->update_status_fn, task->cancel_fn, task->wait_fn);
|
||||
#endif
|
||||
} catch (const std::exception& ex) {
|
||||
BOOST_LOG_TRIVIAL(error) << "task_manager: start_print threw: " << ex.what();
|
||||
@@ -363,12 +369,13 @@ std::map<int, TaskStateInfo*> TaskManager::get_local_task_list()
|
||||
std::map<std::string, TaskStateInfo> TaskManager::get_task_list(int curr_page, int page_count, int& total)
|
||||
{
|
||||
std::map<std::string, TaskStateInfo> out;
|
||||
if (m_agent) {
|
||||
NetworkAgent* agent = m_agent;
|
||||
if (agent) {
|
||||
TaskQueryParams task_query_params;
|
||||
task_query_params.limit = page_count;
|
||||
task_query_params.offset = curr_page * page_count;
|
||||
std::string task_info;
|
||||
int result = m_agent->get_user_tasks(task_query_params, &task_info);
|
||||
int result = agent->get_user_tasks(task_query_params, &task_info);
|
||||
BOOST_LOG_TRIVIAL(trace) << "task_manager: get_task_list task_info=" << task_info;
|
||||
if (result == 0) {
|
||||
try {
|
||||
|
||||
@@ -16,6 +16,7 @@
|
||||
#include <vector>
|
||||
#include <map>
|
||||
#include <mutex>
|
||||
#include <atomic>
|
||||
#include <wx/event.h>
|
||||
|
||||
|
||||
@@ -158,6 +159,8 @@ public:
|
||||
static int SendingInterval;
|
||||
TaskManager(NetworkAgent* agent);
|
||||
|
||||
void set_agent(NetworkAgent* agent);
|
||||
|
||||
int start_print(const std::vector<PrintParams>& params, TaskSettings* settings = nullptr);
|
||||
|
||||
static void set_max_send_at_same_time(int count);
|
||||
@@ -184,7 +187,8 @@ private:
|
||||
std::vector<boost::thread*> m_sending_thread_list;
|
||||
std::mutex m_scedule_mutex;
|
||||
bool m_started { false };
|
||||
NetworkAgent* m_agent { nullptr };
|
||||
// Replaced on the main thread whenever networking is re-initialised, read by the sending threads.
|
||||
std::atomic<NetworkAgent*> m_agent { nullptr };
|
||||
|
||||
std::chrono::system_clock::time_point last_sent_timestamp;
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user