diff --git a/lib/Slic3r/Format/AMF.pm b/lib/Slic3r/Format/AMF.pm index ec6b31fe4..218b1c29d 100644 --- a/lib/Slic3r/Format/AMF.pm +++ b/lib/Slic3r/Format/AMF.pm @@ -36,7 +36,9 @@ sub write_file { printf $fh qq{\n}; printf $fh qq{ Slic3r %s\n}, $Slic3r::VERSION; for my $material_id (sort @{ $model->material_names }) { + next if $material_id eq ''; my $material = $model->get_material($material_id); + # note that material-id must never be 0 since it's reserved by the AMF spec printf $fh qq{ \n}, $material_id; for (keys %{$material->attributes}) { printf $fh qq{ %s\n}, $_, $material->attributes->{$_}; diff --git a/xs/src/libslic3r/Model.cpp b/xs/src/libslic3r/Model.cpp index 8d98b4d6b..29a2f3310 100644 --- a/xs/src/libslic3r/Model.cpp +++ b/xs/src/libslic3r/Model.cpp @@ -690,7 +690,8 @@ ModelVolume::assign_unique_material() { Model* model = this->get_object()->get_model(); - this->_material_id = 1 + model->materials.size(); + // as material-id "0" is reserved by the AMF spec we start from 1 + this->_material_id = 1 + model->materials.size(); // watchout for implicit cast return model->add_material(this->_material_id); }