Bugfix: crash when slicing one layer objects with sailfish G-code flavor. Includes regression test. #2335

This commit is contained in:
Alessandro Ranellucci 2014-11-06 21:06:09 +01:00
parent 11bd1e68e2
commit 30b0869595
4 changed files with 22 additions and 4 deletions

View file

@ -90,7 +90,7 @@ sub change_layer {
my $gcode = "";
if (defined $self->layer_count) {
# TODO: cap this to 99% and add an explicit M73 P100 in the end G-code
$gcode .= $self->writer->update_progress(int(99 * ($self->_layer_index / ($self->layer_count - 1))));
$gcode .= $self->writer->update_progress($self->_layer_index, $self->layer_count);
}
my $z = $layer->print_z + $self->config->z_offset; # in unscaled coordinates

View file

@ -129,11 +129,14 @@ sub set_acceleration {
}
sub update_progress {
my ($self, $percent) = @_;
my ($self, $num, $tot, $allow_100) = @_;
return "" if $self->config->gcode_flavor !~ /^(?:makerware|sailfish)$/;
my $percent = int($num/$tot*100);
$percent = min($percent, 99) if !$allow_100;
return sprintf "M73 P%s%s\n",
int($percent),
$percent,
$self->_comment('update progress');
}

View file

@ -938,6 +938,7 @@ sub write_gcode {
print $fh $gcodegen->retract;
print $fh $gcodegen->writer->set_fan(0);
printf $fh "%s\n", $gcodegen->placeholder_parser->process($self->config->end_gcode);
print $fh $gcodegen->writer->update_progress($gcodegen->layer_count, $gcodegen->layer_count, 1); # 100%
$self->total_used_filament(0);
$self->total_extruded_volume(0);