From 1dfcbf609311cb8acb5827f49c318cde01ac5063 Mon Sep 17 00:00:00 2001 From: "liz.li" Date: Tue, 4 Jul 2023 17:40:02 +0800 Subject: [PATCH] ENH: add nullptr protection Change-Id: I5d853ecebf9007a3d62bc2153b7bd62ff8dc2b4b --- .../GUI/CalibrationWizardPresetPage.cpp | 27 ++++++++++++------- 1 file changed, 17 insertions(+), 10 deletions(-) diff --git a/src/slic3r/GUI/CalibrationWizardPresetPage.cpp b/src/slic3r/GUI/CalibrationWizardPresetPage.cpp index 09775ebb2e..8c745fc7fa 100644 --- a/src/slic3r/GUI/CalibrationWizardPresetPage.cpp +++ b/src/slic3r/GUI/CalibrationWizardPresetPage.cpp @@ -874,20 +874,25 @@ void CalibrationPresetPage::on_recommend_input_value() else if (m_cali_mode == CalibMode::Calib_Flow_Rate && m_cali_stage_panel) { Preset *selected_filament_preset = selected_filaments.begin()->second; if (selected_filament_preset) { - float flow_ratio = selected_filament_preset->config.option("filament_flow_ratio")->get_at(0); - m_cali_stage_panel->set_flow_ratio_value(flow_ratio); + const ConfigOptionFloats* flow_ratio_opt = selected_filament_preset->config.option("filament_flow_ratio"); + if (flow_ratio_opt) { + m_cali_stage_panel->set_flow_ratio_value(flow_ratio_opt->get_at(0)); + } } } else if (m_cali_mode == CalibMode::Calib_Vol_speed_Tower) { Preset* selected_filament_preset = selected_filaments.begin()->second; if (selected_filament_preset) { - double max_volumetric_speed = selected_filament_preset->config.option("filament_max_volumetric_speed")->get_at(0); if (m_custom_range_panel) { - wxArrayString values; - values.push_back(wxString::Format("%.2f", max_volumetric_speed - 5)); - values.push_back(wxString::Format("%.2f", max_volumetric_speed + 5)); - values.push_back(wxString::Format("%.2f", 0.5f)); - m_custom_range_panel->set_values(values); + const ConfigOptionFloats* speed_opt = selected_filament_preset->config.option("filament_max_volumetric_speed"); + if (speed_opt) { + double max_volumetric_speed = speed_opt->get_at(0); + wxArrayString values; + values.push_back(wxString::Format("%.2f", max_volumetric_speed - 5)); + values.push_back(wxString::Format("%.2f", max_volumetric_speed + 5)); + values.push_back(wxString::Format("%.2f", 0.5f)); + m_custom_range_panel->set_values(values); + } } } } @@ -1592,8 +1597,10 @@ void CalibrationPresetPage::get_cali_stage(CaliPresetStage& stage, float& value) if (stage != CaliPresetStage::CALI_MANUAL_STAGE_2) { std::map selected_filaments = get_selected_filaments(); - Preset* preset = selected_filaments.begin()->second; - value = preset->config.option("filament_flow_ratio")->get_at(0); + const ConfigOptionFloats* flow_ratio_opt = selected_filaments.begin()->second->config.option("filament_flow_ratio"); + if (flow_ratio_opt) { + m_cali_stage_panel->set_flow_ratio_value(flow_ratio_opt->get_at(0)); + } } }