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)
{
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.set("presets", "print", prints.get_selected_preset_name());
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
for (const auto& [tbuffer_id, ibuffer_id, path_id, sub_path_id] : paths) {
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];
if (m_tool_colors.size() <= path.extruder_id) return; // invalid data check
#else
for (const auto& [buffer, ibuffer_id, path_id, sub_path_id] : paths) {
const Path& path = buffer->paths[path_id];
@ -4192,6 +4194,7 @@ void GCodeViewer::render_legend() const
{
// shows only extruders actually used
for (unsigned char i : m_extruder_ids) {
if(m_tool_colors.size() > i)
append_item(EItemType::Rect, m_tool_colors[i], _u8L("Extruder") + " " + std::to_string(i + 1));
}
break;
@ -4200,6 +4203,7 @@ void GCodeViewer::render_legend() const
{
// shows only filament actually used
for (unsigned char i : m_extruder_ids) {
if (m_filament_colors.size() > i)
append_item(EItemType::Rect, m_filament_colors[i], _u8L("Filament") + " " + std::to_string(i + 1));
}
break;
@ -4232,6 +4236,7 @@ void GCodeViewer::render_legend() const
{
// shows only extruders actually used
for (unsigned char i : m_extruder_ids) {
if (m_tool_colors.size() > i) {
std::vector<std::pair<Color, std::pair<double, double>>> cp_values = color_print_ranges(i, custom_gcode_per_print_z);
const int items_cnt = static_cast<int>(cp_values.size());
if (items_cnt == 0) { // There are no color changes, but there are some pause print or custom Gcode
@ -4258,6 +4263,7 @@ void GCodeViewer::render_legend() const
}
}
}
}
break;
}
case EViewType::ExtruderTemp: { append_range(m_extrusions.ranges.extruder_temp, 3); break; }

View File

@ -5961,7 +5961,15 @@ void Plater::on_config_change(const DynamicPrintConfig &config)
{
bool update_scheduled = false;
bool bed_shape_changed = false;
auto diffs = 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")
{
update_scheduled = true; // update should be scheduled (for update 3DScene) #2738