From 2bf219a637f9ee539f526ba55c8b79a9d931ef99 Mon Sep 17 00:00:00 2001 From: Alessandro Ranellucci Date: Thu, 9 Aug 2012 00:41:03 +0200 Subject: [PATCH] Bugfix: random failure to load presets. #600 --- lib/Slic3r/Config.pm | 8 +++++++- lib/Slic3r/GUI/Plater.pm | 2 +- lib/Slic3r/GUI/Tab.pm | 6 ++++-- 3 files changed, 12 insertions(+), 4 deletions(-) diff --git a/lib/Slic3r/Config.pm b/lib/Slic3r/Config.pm index 1c24b363b..a0863ef8c 100644 --- a/lib/Slic3r/Config.pm +++ b/lib/Slic3r/Config.pm @@ -930,6 +930,12 @@ sub set_ifndef { if !defined $self->get($opt_key); } +sub has { + my $self = shift; + my ($opt_key) = @_; + return exists $self->{$opt_key}; +} + sub serialize { my $self = shift; my ($opt_key) = @_; @@ -1082,7 +1088,7 @@ sub replace_options { # build a regexp to match the available options my $options = join '|', grep !$Slic3r::Config::Options->{$_}{multiline}, - grep exists $self->{$_}, + grep $self->has($_), keys %{$Slic3r::Config::Options}; # use that regexp to search and replace option names with option values diff --git a/lib/Slic3r/GUI/Plater.pm b/lib/Slic3r/GUI/Plater.pm index 8d3dfb122..1c141fbf6 100644 --- a/lib/Slic3r/GUI/Plater.pm +++ b/lib/Slic3r/GUI/Plater.pm @@ -717,7 +717,7 @@ sub on_config_change { pop @$choices; } $self->Layout; - } elsif (exists $self->{config}{$opt_key}) { + } elsif ($self->{config}->has($opt_key)) { $self->{config}->set($opt_key, $value); $self->_update_bed_size if $opt_key eq 'bed_size'; } diff --git a/lib/Slic3r/GUI/Tab.pm b/lib/Slic3r/GUI/Tab.pm index 1fef481a8..23159a56d 100644 --- a/lib/Slic3r/GUI/Tab.pm +++ b/lib/Slic3r/GUI/Tab.pm @@ -182,7 +182,8 @@ sub on_select_preset { eval { local $SIG{__WARN__} = Slic3r::GUI::warning_catcher($self); foreach my $opt_key (@{$self->{options}}) { - $self->{config}->set($opt_key, $preset_config->get($opt_key)); + $self->{config}->set($opt_key, $preset_config->get($opt_key)) + if $preset_config->has($opt_key); } }; Slic3r::GUI::catch_error($self); @@ -211,7 +212,8 @@ sub get_preset_config { # apply preset values on top of defaults my $external_config = Slic3r::Config->load($preset->{file}); - $config->set($_, $external_config->get($_)) for @{$self->{options}}; + $config->set($_, $external_config->get($_)) + for grep $external_config->has($_), @{$self->{options}}; } return $config;