From e4747c89ae204cdcc8a4e1de1801811e7321593e Mon Sep 17 00:00:00 2001 From: Noisyfox Date: Thu, 28 Nov 2024 13:06:09 +0800 Subject: [PATCH] Lazy init `DiffPresetDialog` --- src/slic3r/GUI/UnsavedChangesDialog.cpp | 28 ++++++++++++++++++------- src/slic3r/GUI/UnsavedChangesDialog.hpp | 3 +++ 2 files changed, 23 insertions(+), 8 deletions(-) diff --git a/src/slic3r/GUI/UnsavedChangesDialog.cpp b/src/slic3r/GUI/UnsavedChangesDialog.cpp index b47f3c0389c..2b6ae57aac7 100644 --- a/src/slic3r/GUI/UnsavedChangesDialog.cpp +++ b/src/slic3r/GUI/UnsavedChangesDialog.cpp @@ -2056,16 +2056,19 @@ DiffPresetDialog::DiffPresetDialog(MainFrame* mainframe) // From the very beginning set dialog font to the wxSYS_DEFAULT_GUI_FONT this->SetFont(wxSystemSettings::GetFont(wxSYS_DEFAULT_GUI_FONT)); #endif // __WXMSW__ +} - // Init bundles - - assert(wxGetApp().preset_bundle); +void DiffPresetDialog::ensure_inited() +{ + if (inited) { + return; + } + inited = true; - m_preset_bundle_left = std::make_unique(*wxGetApp().preset_bundle); - m_preset_bundle_right = std::make_unique(*wxGetApp().preset_bundle); + assert(m_preset_bundle_left.get()); + assert(m_preset_bundle_right.get()); // Create UI items - SetBackgroundColour(*wxWHITE); create_info_lines(); @@ -2083,6 +2086,7 @@ DiffPresetDialog::DiffPresetDialog(MainFrame* mainframe) void DiffPresetDialog::update_controls_visibility(Preset::Type type /* = Preset::TYPE_INVALID*/) { + ensure_inited(); for (auto preset_combos : m_preset_combos) { Preset::Type cb_type = preset_combos.presets_left->get_type(); bool show = type != Preset::TYPE_INVALID ? type == cb_type : @@ -2104,8 +2108,16 @@ void DiffPresetDialog::update_controls_visibility(Preset::Type type /* = Preset: void DiffPresetDialog::update_bundles_from_app() { - *m_preset_bundle_left = *wxGetApp().preset_bundle; - *m_preset_bundle_right = *wxGetApp().preset_bundle; + if (m_preset_bundle_left.get()) { + *m_preset_bundle_left = *wxGetApp().preset_bundle; + } else { + m_preset_bundle_left = std::make_unique(*wxGetApp().preset_bundle); + } + if (m_preset_bundle_right.get()) { + *m_preset_bundle_right = *wxGetApp().preset_bundle; + } else { + m_preset_bundle_right = std::make_unique(*wxGetApp().preset_bundle); + } m_pr_technology = m_preset_bundle_left.get()->printers.get_edited_preset().printer_technology(); } diff --git a/src/slic3r/GUI/UnsavedChangesDialog.hpp b/src/slic3r/GUI/UnsavedChangesDialog.hpp index f91fa844f49..c1cff088562 100644 --- a/src/slic3r/GUI/UnsavedChangesDialog.hpp +++ b/src/slic3r/GUI/UnsavedChangesDialog.hpp @@ -421,6 +421,9 @@ class DiffPresetDialog : public DPIDialog std::unique_ptr m_preset_bundle_left; std::unique_ptr m_preset_bundle_right; + bool inited{false}; + void ensure_inited(); + void create_buttons(); void create_edit_sizer(); void complete_dialog_creation();