mirror of
https://github.com/OrcaSlicer/OrcaSlicer.git
synced 2026-12-01 01:12:59 -05:00
Fix out-of-bounds config reads in the Type1 prime tower (#15183)
Several per-filament and per-extruder options default to a single value. When a config lists fewer values than there are filaments or nozzles, the Type1 prime tower and the pre-heat injector read past the end of the vector, and the same scene could slice to different G-code from one run to the next. - Read `filament_change_length`, `filament_change_length_nc` and `hotend_cooling_rate` with the same fallback to the first value that `get_at()` uses. - `is_nil(idx)` falls back to the first value like `get_at()` instead of reading past the end. - Skip the pre-cooling and last-layer reads when `get_extruder_id()` returns -1, and when no wall filament matches the selected category. - Bounds-check the pre-heat injector's per-filament and per-extruder reads, and use the extruder index when `physical_extruder_map` is too short. Configs that list a value for every filament and nozzle produce the same G-code as before. Adds a test that nozzle-change ramming extrudes the same length in both directions when `filament_change_length` has one value for two filaments.
This commit is contained in:
1 parent
f2037c1d48
commit
a07bc8ff5b
4 files changed
+127
-25
No files matched your search
@@ -131,6 +131,14 @@ inline float align_floor(float value, float base)
|
||||
return std::floor((value) / base) * base;
|
||||
}
|
||||
|
||||
// ConfigOptionVector::get_at() for the vectors copied out of the config.
|
||||
template<class T> static inline T at_or_front(const std::vector<T> &v, size_t i)
|
||||
{
|
||||
if (v.empty())
|
||||
return T(0);
|
||||
return i < v.size() ? v[i] : v.front();
|
||||
}
|
||||
|
||||
static bool is_valid_gcode(const std::string &gcode)
|
||||
{
|
||||
int str_size = gcode.size();
|
||||
@@ -2139,7 +2147,6 @@ void WipeTower::set_extruder(size_t idx, const PrintConfig& config)
|
||||
m_filpar[idx].precool_target_temp.second = 0;
|
||||
float nozzle_temp_first_layer = config.nozzle_temperature_initial_layer.is_nil(idx) ? -1.f : float(config.nozzle_temperature_initial_layer.get_at(idx));
|
||||
float nozzle_temp_other_layer = config.nozzle_temperature.is_nil(idx) ? -1.f : float(config.nozzle_temperature.get_at(idx));
|
||||
std::vector<double> hotend_cooling_rates = config.hotend_cooling_rate.values;
|
||||
auto is_need_precooling = [&](bool extruder_change) -> bool
|
||||
{
|
||||
bool res = config.enable_pre_heating.value;
|
||||
@@ -2149,8 +2156,8 @@ void WipeTower::set_extruder(size_t idx, const PrintConfig& config)
|
||||
if (is_need_precooling(true)) {
|
||||
for (int i = 0; i < m_filpar[idx].precool_t.first.size(); i++) {
|
||||
if (config.hotend_cooling_rate.is_nil(i)) continue;
|
||||
m_filpar[idx].precool_t.first[i] = std::max(0.f, nozzle_temp_other_layer - float(config.filament_pre_cooling_temperature.get_at(idx))) / float(hotend_cooling_rates[i]);
|
||||
m_filpar[idx].precool_t_first_layer.first[i] = std::max(0.f, nozzle_temp_first_layer -float(config.filament_pre_cooling_temperature.get_at(idx))) /float(hotend_cooling_rates[i]);
|
||||
m_filpar[idx].precool_t.first[i] = std::max(0.f, nozzle_temp_other_layer - float(config.filament_pre_cooling_temperature.get_at(idx))) / float(config.hotend_cooling_rate.get_at(i));
|
||||
m_filpar[idx].precool_t_first_layer.first[i] = std::max(0.f, nozzle_temp_first_layer -float(config.filament_pre_cooling_temperature.get_at(idx))) /float(config.hotend_cooling_rate.get_at(i));
|
||||
}
|
||||
m_filpar[idx].precool_target_temp.first = config.filament_pre_cooling_temperature.get_at(idx);
|
||||
}
|
||||
@@ -2158,8 +2165,8 @@ void WipeTower::set_extruder(size_t idx, const PrintConfig& config)
|
||||
if (is_need_precooling(false)) {
|
||||
for (int i = 0; i < m_filpar[idx].precool_t.second.size(); i++) {
|
||||
if (config.hotend_cooling_rate.is_nil(i)) continue;
|
||||
m_filpar[idx].precool_t.second[i] = std::max(0.f, nozzle_temp_other_layer - float(config.filament_pre_cooling_temperature_nc.get_at(idx))) / float(hotend_cooling_rates[i]);
|
||||
m_filpar[idx].precool_t_first_layer.second[i] = std::max(0.f, nozzle_temp_first_layer -float(config.filament_pre_cooling_temperature_nc.get_at(idx))) /float(hotend_cooling_rates[i]);
|
||||
m_filpar[idx].precool_t.second[i] = std::max(0.f, nozzle_temp_other_layer - float(config.filament_pre_cooling_temperature_nc.get_at(idx))) / float(config.hotend_cooling_rate.get_at(i));
|
||||
m_filpar[idx].precool_t_first_layer.second[i] = std::max(0.f, nozzle_temp_first_layer -float(config.filament_pre_cooling_temperature_nc.get_at(idx))) /float(config.hotend_cooling_rate.get_at(i));
|
||||
}
|
||||
m_filpar[idx].precool_target_temp.second = config.filament_pre_cooling_temperature_nc.get_at(idx);
|
||||
}
|
||||
@@ -3100,7 +3107,7 @@ WipeTower::WipeTowerInfo::ToolChange WipeTower::set_toolchange(int old_tool, int
|
||||
float length_to_extrude = volume_to_length(wipe_volume, m_perimeter_width, layer_height);
|
||||
float toolchange_gap_width = get_block_gap_width(new_tool,false);
|
||||
float nozzlechange_gap_width = get_block_gap_width(old_tool,true);
|
||||
float filament_change_length = !is_same_extruder(old_tool, new_tool, layer_id) ? m_filaments_change_length.first[old_tool] : m_filaments_change_length.second[old_tool];
|
||||
float filament_change_length = !is_same_extruder(old_tool, new_tool, layer_id) ? at_or_front(m_filaments_change_length.first, old_tool) : at_or_front(m_filaments_change_length.second, old_tool);
|
||||
depth += std::ceil(length_to_extrude / width) * toolchange_gap_width;
|
||||
// depth *= m_extra_spacing;
|
||||
|
||||
@@ -3165,7 +3172,7 @@ void WipeTower::plan_toolchange(float z_par, float layer_height_par, unsigned in
|
||||
|
||||
depth += std::ceil(length_to_extrude / width) * m_perimeter_width;
|
||||
//depth *= m_extra_spacing;
|
||||
float filament_change_length = !is_same_extruder(old_tool, new_tool, layer_id) ? m_filaments_change_length.first[old_tool] : m_filaments_change_length.second[old_tool];
|
||||
float filament_change_length = !is_same_extruder(old_tool, new_tool, layer_id) ? at_or_front(m_filaments_change_length.first, old_tool) : at_or_front(m_filaments_change_length.second, old_tool);
|
||||
float nozzle_change_depth = 0;
|
||||
float nozzle_change_length = 0;
|
||||
if (is_need_ramming(old_tool, new_tool, layer_id)) {
|
||||
@@ -3327,8 +3334,8 @@ bool WipeTower::is_petg_filament(int filament_id) const
|
||||
bool WipeTower::is_need_reverse_travel(int filament_id,bool extruder_change) const
|
||||
{
|
||||
if (extruder_change)
|
||||
return m_filpar[filament_id].ramming_travel_time.first > EPSILON && m_filaments_change_length.first[filament_id]>EPSILON;
|
||||
return m_filpar[filament_id].ramming_travel_time.second > EPSILON && m_filaments_change_length.second[filament_id] > EPSILON;
|
||||
return m_filpar[filament_id].ramming_travel_time.first > EPSILON && at_or_front(m_filaments_change_length.first, filament_id) > EPSILON;
|
||||
return m_filpar[filament_id].ramming_travel_time.second > EPSILON && at_or_front(m_filaments_change_length.second, filament_id) > EPSILON;
|
||||
}
|
||||
|
||||
// BBS: consider both soluable and support properties
|
||||
@@ -3697,8 +3704,11 @@ WipeTower::NozzleChangeResult WipeTower::ramming(int old_filament_id, int new_fi
|
||||
bool need_change_flow = false;
|
||||
float ramming_length = nozzle_change_line_count * (xr - xl);
|
||||
int extruder_id = get_extruder_id(m_current_tool, m_cur_layer_id);
|
||||
float precool_t = extruder_change ? m_filpar[m_current_tool].precool_t.first[extruder_id] : m_filpar[m_current_tool].precool_t.second[extruder_id];
|
||||
float precool_t_first_layer = extruder_change ? m_filpar[m_current_tool].precool_t_first_layer.first[extruder_id] :
|
||||
// -1: the filament is not in this layer's nozzle map.
|
||||
float precool_t = extruder_id < 0 ? 0.f :
|
||||
extruder_change ? m_filpar[m_current_tool].precool_t.first[extruder_id] : m_filpar[m_current_tool].precool_t.second[extruder_id];
|
||||
float precool_t_first_layer = extruder_id < 0 ? 0.f :
|
||||
extruder_change ? m_filpar[m_current_tool].precool_t_first_layer.first[extruder_id] :
|
||||
m_filpar[m_current_tool].precool_t_first_layer.second[extruder_id];
|
||||
float per_cooling_max_speed = nozzle_change_speed;
|
||||
if (extruder_change) {
|
||||
@@ -4308,7 +4318,7 @@ void WipeTower::toolchange_wipe_new(WipeTowerWriter &writer, const box_coordinat
|
||||
if (should_cooling_before_object) {
|
||||
int n = (cleaning_box.lu[1] - cleaning_box.ld[1]) / dy;
|
||||
int extruder_id = get_extruder_id(m_current_tool, m_cur_layer_id);
|
||||
float cooling_time = (m_filpar[m_current_tool].filament_tower_interface_print_temp - m_filpar[m_current_tool].nozzle_temperature) / m_hotend_cooling_rate[extruder_id];
|
||||
float cooling_time = (m_filpar[m_current_tool].filament_tower_interface_print_temp - m_filpar[m_current_tool].nozzle_temperature) / at_or_front(m_hotend_cooling_rate, extruder_id);
|
||||
if (n < 2) {
|
||||
float estimate_time = estimate_wipe_time(0);
|
||||
speed_factor = estimate_time > cooling_time? 1: estimate_time / cooling_time;
|
||||
@@ -4485,8 +4495,10 @@ void WipeTower::set_nozzle_last_layer_id()
|
||||
for(int i =0 ; i<info.tool_changes.size();i++) {
|
||||
int old_tool = info.tool_changes[i].old_tool;
|
||||
int new_tool = info.tool_changes[i].new_tool;
|
||||
if (old_tool >= 0) m_last_layer_id[get_extruder_id(old_tool, idx)] = idx;
|
||||
m_last_layer_id[get_extruder_id(new_tool, idx)] = idx;
|
||||
if (int ex = old_tool >= 0 ? get_extruder_id(old_tool, idx) : -1; ex >= 0 && ex < (int) m_last_layer_id.size())
|
||||
m_last_layer_id[ex] = idx;
|
||||
if (int ex = get_extruder_id(new_tool, idx); ex >= 0 && ex < (int) m_last_layer_id.size())
|
||||
m_last_layer_id[ex] = idx;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -4957,6 +4969,9 @@ void WipeTower::generate_new(std::vector<std::vector<WipeTower::ToolChangeResult
|
||||
if (layer.tool_changes.size() == 0)
|
||||
return -1;
|
||||
|
||||
if (wall_filament < 0)
|
||||
return layer.tool_changes[0].new_tool;
|
||||
|
||||
int candidate_id = -1;
|
||||
for (size_t idx = 0; idx < layer.tool_changes.size(); ++idx) {
|
||||
if (idx == 0) {
|
||||
|
||||
Reference in new issue
Block a user