From 8d8dcc36c54b91f0da32bf0d02e3f4a6d9729bc9 Mon Sep 17 00:00:00 2001 From: Stone Li Date: Thu, 3 Nov 2022 10:12:31 +0800 Subject: [PATCH] FIX: fix a crash, set APP_MODAL for dialog Change-Id: I80d216df134febdcefd2fd5f3859bdb62c1b81bd Signed-off-by: Stone Li --- src/slic3r/GUI/DeviceManager.cpp | 2 +- src/slic3r/GUI/UpgradePanel.cpp | 46 +++++++++++++++++--------------- 2 files changed, 26 insertions(+), 22 deletions(-) diff --git a/src/slic3r/GUI/DeviceManager.cpp b/src/slic3r/GUI/DeviceManager.cpp index a5753202e..4bc670b6f 100644 --- a/src/slic3r/GUI/DeviceManager.cpp +++ b/src/slic3r/GUI/DeviceManager.cpp @@ -300,7 +300,7 @@ void MachineObject::set_access_code(std::string code) bool MachineObject::is_lan_mode_printer() { bool result = false; - if (connection_type() == "lan") + if (!dev_connection_type.empty() && dev_connection_type == "lan") return true; return result; } diff --git a/src/slic3r/GUI/UpgradePanel.cpp b/src/slic3r/GUI/UpgradePanel.cpp index 7dc39ae08..857e202f6 100644 --- a/src/slic3r/GUI/UpgradePanel.cpp +++ b/src/slic3r/GUI/UpgradePanel.cpp @@ -660,32 +660,30 @@ void MachineInfoPanel::upgrade_firmware_internal() { void MachineInfoPanel::on_upgrade_firmware(wxCommandEvent &event) { - ConfirmHintDialog* confirm_dlg = new ConfirmHintDialog(this->GetParent(), wxID_ANY, _L("Upgrade firmware")); - confirm_dlg->SetHint(_L( + ConfirmHintDialog confirm_dlg(this->GetParent(), wxID_ANY, _L("Upgrade firmware")); + confirm_dlg.SetHint(_L( "Are you sure you want to update? This will take about 10 minutes. Do not turn off the power while the printer is updating." )); - confirm_dlg->Bind(EVT_CONFIRM_HINT, [this](wxCommandEvent &e) { + confirm_dlg.Bind(EVT_CONFIRM_HINT, [this](wxCommandEvent &e) { if (m_obj){ m_obj->command_upgrade_confirm(); } }); - if(confirm_dlg->ShowModal()) - delete confirm_dlg; + confirm_dlg.ShowModal(); } void MachineInfoPanel::on_consisitency_upgrade_firmware(wxCommandEvent &event) { - ConfirmHintDialog* confirm_dlg = new ConfirmHintDialog(this->GetParent(), wxID_ANY, _L("Upgrade firmware")); - confirm_dlg->SetHint(_L( + ConfirmHintDialog confirm_dlg(this->GetParent(), wxID_ANY, _L("Upgrade firmware")); + confirm_dlg.SetHint(_L( "Are you sure you want to update? This will take about 10 minutes. Do not turn off the power while the printer is updating." )); - confirm_dlg->Bind(EVT_CONFIRM_HINT, [this](wxCommandEvent &e) { + confirm_dlg.Bind(EVT_CONFIRM_HINT, [this](wxCommandEvent &e) { if (m_obj){ m_obj->command_consistency_upgrade_confirm(); } }); - if(confirm_dlg->ShowModal()) - delete confirm_dlg; + confirm_dlg.ShowModal(); } void MachineInfoPanel::on_show_release_note(wxMouseEvent &event) @@ -800,13 +798,16 @@ void UpgradePanel::update(MachineObject *obj) if (m_obj && m_show_forced_hint) { if (m_obj->upgrade_force_upgrade) { m_show_forced_hint = false; //lock hint - ConfirmHintDialog* force_dlg = new ConfirmHintDialog(m_scrolledWindow, wxID_ANY, _L("Upgrade firmware")); - force_dlg->SetHint(_L( + ConfirmHintDialog force_dlg(m_scrolledWindow, wxID_ANY, _L("Upgrade firmware"), ConfirmHintDialog::CONFIRM_AND_CANCEL, wxDefaultPosition, wxDefaultSize, wxPD_APP_MODAL); + force_dlg.SetHint(_L( "An important update was detected and needs to be run before printing can continue. Do you want to update now? You can also update later from 'Upgrade firmware'." )); - force_dlg->Bind(EVT_CONFIRM_HINT, &MachineInfoPanel::on_upgrade_firmware, m_push_upgrade_panel); - if (force_dlg->ShowModal()) - delete force_dlg; + force_dlg.Bind(EVT_CONFIRM_HINT, [this](wxCommandEvent& e) { + if (m_obj) { + m_obj->command_upgrade_confirm(); + } + }); + force_dlg.ShowModal(); } } @@ -818,13 +819,16 @@ void UpgradePanel::update(MachineObject *obj) if (m_obj && m_show_consistency_hint) { if (m_obj->upgrade_consistency_request) { m_show_consistency_hint = false; - ConfirmHintDialog* consistency_dlg = new ConfirmHintDialog(m_scrolledWindow, wxID_ANY, _L("Upgrade firmware")); - consistency_dlg->SetHint(_L( + ConfirmHintDialog consistency_dlg(m_scrolledWindow, wxID_ANY, _L("Upgrade firmware"), ConfirmHintDialog::CONFIRM_AND_CANCEL, wxDefaultPosition, wxDefaultSize, wxPD_APP_MODAL); + consistency_dlg.SetHint(_L( "The firmware version is abnormal. Repairing and updating are required before printing. Do you want to update now? You can also update later on printer or update next time starting the studio." )); - consistency_dlg->Bind(EVT_CONFIRM_HINT, &MachineInfoPanel::on_consisitency_upgrade_firmware, m_push_upgrade_panel); - if (consistency_dlg->ShowModal()) - delete consistency_dlg; + consistency_dlg.Bind(EVT_CONFIRM_HINT, [this](wxCommandEvent& e) { + if (m_obj) { + m_obj->command_consistency_upgrade_confirm(); + } + }); + consistency_dlg.ShowModal(); } } @@ -914,4 +918,4 @@ bool UpgradePanel::Show(bool show) } } -} \ No newline at end of file +}