Fix crash when gcode data is not valid

and comment a problematic assert that get trigger are startup
This commit is contained in:
remi durand 2021-06-12 17:32:56 +02:00
parent fbd9f1506f
commit 012595e107
3 changed files with 38 additions and 24 deletions

View File

@ -470,7 +470,7 @@ void PresetBundle::load_selections(AppConfig &config, const std::string &preferr
void PresetBundle::export_selections(AppConfig &config) void PresetBundle::export_selections(AppConfig &config)
{ {
assert(this->printers.get_edited_preset().printer_technology() != ptFFF || filament_presets.size() >= 1); assert(this->printers.get_edited_preset().printer_technology() != ptFFF || filament_presets.size() >= 1);
assert(this->printers.get_edited_preset().printer_technology() != ptFFF || filament_presets.size() > 1 || filaments.get_selected_preset_name() == filament_presets.front()); //assert(this->printers.get_edited_preset().printer_technology() != ptFFF || filament_presets.size() > 1 || filaments.get_selected_preset_name() == filament_presets.front());
config.clear_section("presets"); config.clear_section("presets");
config.set("presets", "print", prints.get_selected_preset_name()); config.set("presets", "print", prints.get_selected_preset_name());
config.set("presets", "filament", filament_presets.front()); config.set("presets", "filament", filament_presets.front());

View File

@ -3013,7 +3013,9 @@ void GCodeViewer::refresh_render_paths(bool keep_sequential_current_first, bool
#if ENABLE_REDUCED_TOOLPATHS_SEGMENT_CAPS #if ENABLE_REDUCED_TOOLPATHS_SEGMENT_CAPS
for (const auto& [tbuffer_id, ibuffer_id, path_id, sub_path_id] : paths) { for (const auto& [tbuffer_id, ibuffer_id, path_id, sub_path_id] : paths) {
TBuffer& buffer = const_cast<TBuffer&>(m_buffers[tbuffer_id]); TBuffer& buffer = const_cast<TBuffer&>(m_buffers[tbuffer_id]);
if (buffer.paths.size() <= path_id) return; // invalid data check
const Path& path = buffer.paths[path_id]; const Path& path = buffer.paths[path_id];
if (m_tool_colors.size() <= path.extruder_id) return; // invalid data check
#else #else
for (const auto& [buffer, ibuffer_id, path_id, sub_path_id] : paths) { for (const auto& [buffer, ibuffer_id, path_id, sub_path_id] : paths) {
const Path& path = buffer->paths[path_id]; const Path& path = buffer->paths[path_id];
@ -4192,7 +4194,8 @@ void GCodeViewer::render_legend() const
{ {
// shows only extruders actually used // shows only extruders actually used
for (unsigned char i : m_extruder_ids) { for (unsigned char i : m_extruder_ids) {
append_item(EItemType::Rect, m_tool_colors[i], _u8L("Extruder") + " " + std::to_string(i + 1)); if(m_tool_colors.size() > i)
append_item(EItemType::Rect, m_tool_colors[i], _u8L("Extruder") + " " + std::to_string(i + 1));
} }
break; break;
} }
@ -4200,7 +4203,8 @@ void GCodeViewer::render_legend() const
{ {
// shows only filament actually used // shows only filament actually used
for (unsigned char i : m_extruder_ids) { for (unsigned char i : m_extruder_ids) {
append_item(EItemType::Rect, m_filament_colors[i], _u8L("Filament") + " " + std::to_string(i + 1)); if (m_filament_colors.size() > i)
append_item(EItemType::Rect, m_filament_colors[i], _u8L("Filament") + " " + std::to_string(i + 1));
} }
break; break;
} }
@ -4232,28 +4236,30 @@ void GCodeViewer::render_legend() const
{ {
// shows only extruders actually used // shows only extruders actually used
for (unsigned char i : m_extruder_ids) { for (unsigned char i : m_extruder_ids) {
std::vector<std::pair<Color, std::pair<double, double>>> cp_values = color_print_ranges(i, custom_gcode_per_print_z); if (m_tool_colors.size() > i) {
const int items_cnt = static_cast<int>(cp_values.size()); std::vector<std::pair<Color, std::pair<double, double>>> cp_values = color_print_ranges(i, custom_gcode_per_print_z);
if (items_cnt == 0) { // There are no color changes, but there are some pause print or custom Gcode const int items_cnt = static_cast<int>(cp_values.size());
append_item(EItemType::Rect, m_tool_colors[i], _u8L("Extruder") + " " + std::to_string(i + 1) + " " + _u8L("default color")); if (items_cnt == 0) { // There are no color changes, but there are some pause print or custom Gcode
} append_item(EItemType::Rect, m_tool_colors[i], _u8L("Extruder") + " " + std::to_string(i + 1) + " " + _u8L("default color"));
else { }
for (int j = items_cnt; j >= 0; --j) { else {
// create label for color change item for (int j = items_cnt; j >= 0; --j) {
std::string label = _u8L("Extruder") + " " + std::to_string(i + 1); // create label for color change item
if (j == 0) { std::string label = _u8L("Extruder") + " " + std::to_string(i + 1);
label += " " + upto_label(cp_values.front().second.first); if (j == 0) {
append_item(EItemType::Rect, m_tool_colors[i], label); label += " " + upto_label(cp_values.front().second.first);
break; append_item(EItemType::Rect, m_tool_colors[i], label);
} break;
else if (j == items_cnt) { }
label += " " + above_label(cp_values[j - 1].second.second); else if (j == items_cnt) {
append_item(EItemType::Rect, cp_values[j - 1].first, label); label += " " + above_label(cp_values[j - 1].second.second);
continue; append_item(EItemType::Rect, cp_values[j - 1].first, label);
} continue;
}
label += " " + fromto_label(cp_values[j - 1].second.second, cp_values[j].second.first); label += " " + fromto_label(cp_values[j - 1].second.second, cp_values[j].second.first);
append_item(EItemType::Rect, cp_values[j - 1].first, label); append_item(EItemType::Rect, cp_values[j - 1].first, label);
}
} }
} }
} }

View File

@ -5961,7 +5961,15 @@ void Plater::on_config_change(const DynamicPrintConfig &config)
{ {
bool update_scheduled = false; bool update_scheduled = false;
bool bed_shape_changed = false; bool bed_shape_changed = false;
auto diffs = p->config->diff(config);
for (auto opt_key : p->config->diff(config)) { for (auto opt_key : p->config->diff(config)) {
if (opt_key == "nozzle_diameter") {
if (p->config->option<ConfigOptionFloats>(opt_key)->values.size() > config.option<ConfigOptionFloats>(opt_key)->values.size()) {
//lower number of extuders, please don't try to display the old gcode.
p->reset_gcode_toolpaths();
p->gcode_result.reset();
}
}
if (opt_key == "filament_colour") if (opt_key == "filament_colour")
{ {
update_scheduled = true; // update should be scheduled (for update 3DScene) #2738 update_scheduled = true; // update should be scheduled (for update 3DScene) #2738