From d1bb69434e3de4f28effe4c03fc591a150240c57 Mon Sep 17 00:00:00 2001 From: Alessandro Ranellucci Date: Tue, 25 Mar 2014 19:06:51 +0100 Subject: [PATCH] Handle non existing STL files gracefully --- lib/Slic3r/Format/STL.pm | 5 ++++- lib/Slic3r/GUI/Plater.pm | 6 ++++-- 2 files changed, 8 insertions(+), 3 deletions(-) diff --git a/lib/Slic3r/Format/STL.pm b/lib/Slic3r/Format/STL.pm index 8ebc56787..d53a61ad3 100644 --- a/lib/Slic3r/Format/STL.pm +++ b/lib/Slic3r/Format/STL.pm @@ -7,8 +7,11 @@ sub read_file { my $self = shift; my ($file) = @_; + my $path = Slic3r::encode_path($file); + die "Failed to open $file\n" if !-e $path; + my $mesh = Slic3r::TriangleMesh->new; - $mesh->ReadSTLFile(Slic3r::encode_path($file)); + $mesh->ReadSTLFile($path); $mesh->repair; my $model = Slic3r::Model->new; diff --git a/lib/Slic3r/GUI/Plater.pm b/lib/Slic3r/GUI/Plater.pm index 6cfc54856..bc13ed44b 100644 --- a/lib/Slic3r/GUI/Plater.pm +++ b/lib/Slic3r/GUI/Plater.pm @@ -382,10 +382,12 @@ sub load_file { my $model = eval { Slic3r::Model->read_from_file($input_file) }; Slic3r::GUI::show_error($self, $@) if $@; - $self->load_model_objects(@{$model->objects}); + if (defined $model) { + $self->load_model_objects(@{$model->objects}); + $self->statusbar->SetStatusText("Loaded " . basename($input_file)); + } $process_dialog->Destroy; - $self->statusbar->SetStatusText("Loaded " . basename($input_file)); } sub load_model_objects {