From f11196525b8e61823f9b3eba44c16397ed5e8462 Mon Sep 17 00:00:00 2001 From: Alessandro Ranellucci Date: Sun, 18 Jan 2015 12:12:10 +0100 Subject: [PATCH] Handle empty STL files gracefully instead of crashing. #2557 --- lib/Slic3r/Format/STL.pm | 3 +++ lib/Slic3r/Model.pm | 3 +++ 2 files changed, 6 insertions(+) diff --git a/lib/Slic3r/Format/STL.pm b/lib/Slic3r/Format/STL.pm index c9fc303ff..11928d8b2 100644 --- a/lib/Slic3r/Format/STL.pm +++ b/lib/Slic3r/Format/STL.pm @@ -14,6 +14,9 @@ sub read_file { $mesh->ReadSTLFile($path); $mesh->repair; + die "This STL file couldn't be read because it's empty.\n" + if $mesh->facets_count == 0; + my $model = Slic3r::Model->new; my $basename = basename($file); diff --git a/lib/Slic3r/Model.pm b/lib/Slic3r/Model.pm index a7a3009ae..1a2f62afd 100644 --- a/lib/Slic3r/Model.pm +++ b/lib/Slic3r/Model.pm @@ -12,6 +12,9 @@ sub read_from_file { : $input_file =~ /\.amf(\.xml)?$/i ? Slic3r::Format::AMF->read_file($input_file) : die "Input file must have .stl, .obj or .amf(.xml) extension\n"; + die "The supplied file couldn't be read because it's empty.\n" + if $model->objects_count == 0; + $_->set_input_file($input_file) for @{$model->objects}; return $model; }