mirror of
https://git.mirrors.martin98.com/https://github.com/prusa3d/PrusaSlicer.git
synced 2025-07-31 01:06:57 +08:00
SPE-2270 - Fixed crash when adding color change
This commit is contained in:
parent
5bbc430e53
commit
9f77f9c643
@ -1987,7 +1987,7 @@ static std::string emit_custom_color_change_gcode_per_print_z(
|
||||
|
||||
int color_change_extruder = -1;
|
||||
if (color_change && custom_gcode.extruder > 0)
|
||||
color_change_extruder = custom_gcode.extruder - 1;
|
||||
color_change_extruder = single_extruder_printer ? 0 : custom_gcode.extruder - 1;
|
||||
|
||||
assert(color_change_extruder >= 0);
|
||||
// Color Change or Tool Change as Color Change.
|
||||
|
@ -1014,8 +1014,7 @@ void GCodeViewer::load_as_gcode(const GCodeProcessorResult& gcode_result, const
|
||||
m_extruders_count = gcode_result.extruders_count;
|
||||
m_sequential_view.gcode_window.load_gcode(gcode_result);
|
||||
|
||||
if (wxGetApp().is_gcode_viewer())
|
||||
m_custom_gcode_per_print_z = gcode_result.custom_gcode_per_print_z;
|
||||
m_custom_gcode_per_print_z = gcode_result.custom_gcode_per_print_z;
|
||||
|
||||
m_max_print_height = gcode_result.max_print_height;
|
||||
m_z_offset = gcode_result.z_offset;
|
||||
@ -2399,11 +2398,10 @@ void GCodeViewer::render_legend(float& legend_height)
|
||||
break;
|
||||
}
|
||||
case libvgcode::EViewType::ColorPrint: {
|
||||
const std::vector<CustomGCode::Item>& custom_gcode_per_print_z = wxGetApp().is_editor() ? wxGetApp().plater()->model().custom_gcode_per_print_z.gcodes : m_custom_gcode_per_print_z;
|
||||
size_t total_items = 1;
|
||||
const std::vector<uint8_t>& used_extruders_ids = m_viewer.get_used_extruders_ids();
|
||||
for (uint8_t extruder_id : used_extruders_ids) {
|
||||
total_items += color_print_ranges(extruder_id, custom_gcode_per_print_z).size();
|
||||
total_items += color_print_ranges(extruder_id, m_custom_gcode_per_print_z).size();
|
||||
}
|
||||
|
||||
const bool need_scrollable = static_cast<float>(total_items) * icon_size + (static_cast<float>(total_items) - 1.0f) * ImGui::GetStyle().ItemSpacing.y > child_height;
|
||||
@ -2412,7 +2410,7 @@ void GCodeViewer::render_legend(float& legend_height)
|
||||
if (need_scrollable)
|
||||
ImGui::BeginChild("color_prints", { -1.0f, child_height }, false);
|
||||
if (get_extruders_count() == 1) { // single extruder use case
|
||||
const std::vector<std::pair<ColorRGBA, std::pair<double, double>>> cp_values = color_print_ranges(0, custom_gcode_per_print_z);
|
||||
const std::vector<std::pair<ColorRGBA, std::pair<double, double>>> cp_values = color_print_ranges(0, m_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
|
||||
append_item(EItemType::Rect, libvgcode::convert(m_viewer.get_tool_colors().front()), _u8L("Default color"));
|
||||
@ -2435,7 +2433,7 @@ void GCodeViewer::render_legend(float& legend_height)
|
||||
// shows only extruders actually used
|
||||
const std::vector<uint8_t>& used_extruders_ids = m_viewer.get_used_extruders_ids();
|
||||
for (uint8_t extruder_id : used_extruders_ids) {
|
||||
const std::vector<std::pair<ColorRGBA, std::pair<double, double>>> cp_values = color_print_ranges(extruder_id, custom_gcode_per_print_z);
|
||||
const std::vector<std::pair<ColorRGBA, std::pair<double, double>>> cp_values = color_print_ranges(extruder_id, m_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
|
||||
@ -2497,7 +2495,7 @@ void GCodeViewer::render_legend(float& legend_height)
|
||||
auto generate_partial_times = [this, get_used_filament_from_volume](const TimesList& times, const std::vector<double>& used_filaments) {
|
||||
PartialTimes items;
|
||||
|
||||
std::vector<CustomGCode::Item> custom_gcode_per_print_z = wxGetApp().is_editor() ? wxGetApp().plater()->model().custom_gcode_per_print_z.gcodes : m_custom_gcode_per_print_z;
|
||||
std::vector<CustomGCode::Item> custom_gcode_per_print_z = m_custom_gcode_per_print_z;
|
||||
const size_t extruders_count = get_extruders_count();
|
||||
std::vector<ColorRGBA> last_color(extruders_count);
|
||||
for (size_t i = 0; i < extruders_count; ++i) {
|
||||
|
@ -573,7 +573,6 @@ private:
|
||||
if (!is_tool_change && it->extruder == static_cast<int>(extruder_id + 1))
|
||||
return m600_color_id(it);
|
||||
|
||||
assert(false);
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user