Skip to content

Commit

Permalink
Fixed crashes caused by pressure eq when support is used (#3407)
Browse files Browse the repository at this point in the history
Fixed crashed caused by pressure eq when support is used
  • Loading branch information
SoftFever authored Jan 1, 2024
1 parent 967dc3d commit 2f916f5
Show file tree
Hide file tree
Showing 5 changed files with 19 additions and 199 deletions.
2 changes: 0 additions & 2 deletions src/libslic3r/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -81,8 +81,6 @@ set(lisbslic3r_sources
ExtrusionEntity.hpp
ExtrusionEntityCollection.cpp
ExtrusionEntityCollection.hpp
ExtrusionRole.cpp
ExtrusionRole.hpp
ExtrusionSimulator.cpp
ExtrusionSimulator.hpp
FileParserError.hpp
Expand Down
94 changes: 0 additions & 94 deletions src/libslic3r/ExtrusionRole.cpp

This file was deleted.

83 changes: 0 additions & 83 deletions src/libslic3r/ExtrusionRole.hpp

This file was deleted.

32 changes: 16 additions & 16 deletions src/libslic3r/GCode/PressureEqualizer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
///|/
///|/ PrusaSlicer is released under the terms of the AGPLv3 or higher
///|/
#include <iostream>
#include <memory.h>
#include <cstring>
#include <cfloat>
Expand Down Expand Up @@ -45,7 +46,7 @@ PressureEqualizer::PressureEqualizer(const Slic3r::GCodeConfig &config) : m_use_
m_current_extruder = 0;
// Zero the position of the XYZE axes + the current feed
memset(m_current_pos, 0, sizeof(float) * 5);
m_current_extrusion_role = GCodeExtrusionRole::None;
m_current_extrusion_role = ExtrusionRole::erNone;
// Expect the first command to fill the nozzle (deretract).
m_retracted = true;

Expand Down Expand Up @@ -74,7 +75,7 @@ PressureEqualizer::PressureEqualizer(const Slic3r::GCodeConfig &config) : m_use_
}

// Don't regulate the pressure before and after ironing.
for (const GCodeExtrusionRole er : {GCodeExtrusionRole::Ironing}) {
for (const ExtrusionRole er : {ExtrusionRole::erIroning}) {
m_max_volumetric_extrusion_rate_slopes[size_t(er)].negative = 0;
m_max_volumetric_extrusion_rate_slopes[size_t(er)].positive = 0;
}
Expand Down Expand Up @@ -260,7 +261,7 @@ bool PressureEqualizer::process_line(const char *line, const char *line_end, GCo
if (strncmp(line, EXTRUSION_ROLE_TAG.data(), EXTRUSION_ROLE_TAG.length()) == 0) {
line += EXTRUSION_ROLE_TAG.length();
int role = atoi(line);
m_current_extrusion_role = GCodeExtrusionRole(role);
m_current_extrusion_role = ExtrusionRole(role);
#ifdef PRESSURE_EQUALIZER_DEBUG
++line_idx;
#endif
Expand Down Expand Up @@ -589,8 +590,7 @@ void PressureEqualizer::adjust_volumetric_rate(const size_t fist_line_idx, const
if (line_idx == fist_line_idx || !m_gcode_lines[line_idx].extruding())
// Nothing to do, the last move is not extruding.
return;

std::array<float, size_t(GCodeExtrusionRole::Count)> feedrate_per_extrusion_role{};
std::array<float, size_t(ExtrusionRole::erCount)> feedrate_per_extrusion_role{};
feedrate_per_extrusion_role.fill(std::numeric_limits<float>::max());
feedrate_per_extrusion_role[int(m_gcode_lines[line_idx].extrusion_role)] = m_gcode_lines[line_idx].volumetric_extrusion_rate_start;

Expand All @@ -600,7 +600,7 @@ void PressureEqualizer::adjust_volumetric_rate(const size_t fist_line_idx, const
if (!m_gcode_lines[idx_prev].extruding())
break;
// Don't decelerate before ironing.
if (m_gcode_lines[line_idx].extrusion_role == GCodeExtrusionRole::Ironing) { line_idx = idx_prev;
if (m_gcode_lines[line_idx].extrusion_role == ExtrusionRole::erIroning) { line_idx = idx_prev;
continue;
}
// Volumetric extrusion rate at the start of the succeding segment.
Expand All @@ -609,18 +609,18 @@ void PressureEqualizer::adjust_volumetric_rate(const size_t fist_line_idx, const
line_idx = idx_prev;
GCodeLine &line = m_gcode_lines[line_idx];

for (size_t iRole = 1; iRole < size_t(GCodeExtrusionRole::Count); ++ iRole) {
for (size_t iRole = 1; iRole < size_t(ExtrusionRole::erCount); ++ iRole) {
const float &rate_slope = m_max_volumetric_extrusion_rate_slopes[iRole].negative;
if (rate_slope == 0 || feedrate_per_extrusion_role[iRole] == std::numeric_limits<float>::max())
continue; // The negative rate is unlimited or the rate for GCodeExtrusionRole iRole is unlimited.
continue; // The negative rate is unlimited or the rate for ExtrusionRole iRole is unlimited.

float rate_end = feedrate_per_extrusion_role[iRole];
if (iRole == size_t(line.extrusion_role) && rate_succ < rate_end)
// Limit by the succeeding volumetric flow rate.
rate_end = rate_succ;

// don't alter the flow rate for these extrusion types
if (!line.adjustable_flow || line.extrusion_role == GCodeExtrusionRole::BridgeInfill || line.extrusion_role == GCodeExtrusionRole::Ironing) {
if (!line.adjustable_flow || line.extrusion_role == ExtrusionRole::erBridgeInfill || line.extrusion_role == ExtrusionRole::erIroning) {
rate_end = line.volumetric_extrusion_rate_end;
} else if (line.volumetric_extrusion_rate_end > rate_end) {
line.volumetric_extrusion_rate_end = rate_end;
Expand All @@ -644,7 +644,7 @@ void PressureEqualizer::adjust_volumetric_rate(const size_t fist_line_idx, const
}
// feedrate_per_extrusion_role[iRole] = (iRole == line.extrusion_role) ? line.volumetric_extrusion_rate_start : rate_start;
// Don't store feed rate for ironing
if (line.extrusion_role != GCodeExtrusionRole::Ironing)
if (line.extrusion_role != ExtrusionRole::erIroning)
feedrate_per_extrusion_role[iRole] = line.volumetric_extrusion_rate_start;
}
}
Expand All @@ -659,7 +659,7 @@ void PressureEqualizer::adjust_volumetric_rate(const size_t fist_line_idx, const
if (!m_gcode_lines[idx_next].extruding())
break;
// Don't accelerate after ironing.
if (m_gcode_lines[line_idx].extrusion_role == GCodeExtrusionRole::Ironing) {
if (m_gcode_lines[line_idx].extrusion_role == ExtrusionRole::erIroning) {
line_idx = idx_next;
continue;
}
Expand All @@ -668,14 +668,14 @@ void PressureEqualizer::adjust_volumetric_rate(const size_t fist_line_idx, const
line_idx = idx_next;
GCodeLine &line = m_gcode_lines[line_idx];

for (size_t iRole = 1; iRole < size_t(GCodeExtrusionRole::Count); ++ iRole) {
for (size_t iRole = 1; iRole < size_t(ExtrusionRole::erCount); ++ iRole) {
const float &rate_slope = m_max_volumetric_extrusion_rate_slopes[iRole].positive;
if (rate_slope == 0 || feedrate_per_extrusion_role[iRole] == std::numeric_limits<float>::max())
continue; // The positive rate is unlimited or the rate for GCodeExtrusionRole iRole is unlimited.
continue; // The positive rate is unlimited or the rate for ExtrusionRole iRole is unlimited.

float rate_start = feedrate_per_extrusion_role[iRole];
// don't alter the flow rate for these extrusion types
if (!line.adjustable_flow || line.extrusion_role == GCodeExtrusionRole::BridgeInfill || line.extrusion_role == GCodeExtrusionRole::Ironing) {
if (!line.adjustable_flow || line.extrusion_role == ExtrusionRole::erBridgeInfill || line.extrusion_role == ExtrusionRole::erIroning) {
rate_start = line.volumetric_extrusion_rate_start;
} else if (iRole == size_t(line.extrusion_role) && rate_prec < rate_start)
rate_start = rate_prec;
Expand All @@ -701,7 +701,7 @@ void PressureEqualizer::adjust_volumetric_rate(const size_t fist_line_idx, const
}
// feedrate_per_extrusion_role[iRole] = (iRole == line.extrusion_role) ? line.volumetric_extrusion_rate_end : rate_end;
// Don't store feed rate for ironing
if (line.extrusion_role != GCodeExtrusionRole::Ironing)
if (line.extrusion_role != ExtrusionRole::erIroning)
feedrate_per_extrusion_role[iRole] = line.volumetric_extrusion_rate_end;
}
}
Expand Down Expand Up @@ -785,7 +785,7 @@ void PressureEqualizer::push_line_to_output(const size_t line_idx, const float n
GCodeG1Formatter feedrate_formatter;
feedrate_formatter.emit_f(new_feedrate);
feedrate_formatter.emit_string(std::string(EXTRUDE_SET_SPEED_TAG.data(), EXTRUDE_SET_SPEED_TAG.length()));
if (line.extrusion_role == GCodeExtrusionRole::ExternalPerimeter)
if (line.extrusion_role == ExtrusionRole::erExternalPerimeter)
feedrate_formatter.emit_string(std::string(EXTERNAL_PERIMETER_TAG.data(), EXTERNAL_PERIMETER_TAG.length()));
push_to_output(feedrate_formatter);

Expand Down
7 changes: 3 additions & 4 deletions src/libslic3r/GCode/PressureEqualizer.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@

#include "../libslic3r.h"
#include "../PrintConfig.hpp"
#include "../ExtrusionRole.hpp"

#include <queue>

Expand Down Expand Up @@ -70,7 +69,7 @@ class PressureEqualizer
float positive;
float negative;
};
ExtrusionRateSlope m_max_volumetric_extrusion_rate_slopes[size_t(GCodeExtrusionRole::Count)];
ExtrusionRateSlope m_max_volumetric_extrusion_rate_slopes[size_t(ExtrusionRole::erCount)];
float m_max_volumetric_extrusion_rate_slope_positive;
float m_max_volumetric_extrusion_rate_slope_negative;

Expand All @@ -82,7 +81,7 @@ class PressureEqualizer
// X,Y,Z,E,F
float m_current_pos[5];
size_t m_current_extruder;
GCodeExtrusionRole m_current_extrusion_role;
ExtrusionRole m_current_extrusion_role;
bool m_retracted;
bool m_use_relative_e_distances;

Expand Down Expand Up @@ -158,7 +157,7 @@ class PressureEqualizer
// Index of the active extruder.
size_t extruder_id;
// Extrusion role of this segment.
GCodeExtrusionRole extrusion_role;
ExtrusionRole extrusion_role;

// Current volumetric extrusion rate.
float volumetric_extrusion_rate;
Expand Down

0 comments on commit 2f916f5

Please sign in to comment.