From 4083b3380712b1a3ab6f799c5652c22669667653 Mon Sep 17 00:00:00 2001 From: Alessandro Ranellucci Date: Mon, 9 Feb 2015 11:00:44 +0100 Subject: [PATCH] Bugfix: crash on version check on Linux. #2641 --- lib/Slic3r/GUI.pm | 43 +++++++++++++++++++++++-------------- lib/Slic3r/GUI/MainFrame.pm | 2 +- 2 files changed, 28 insertions(+), 17 deletions(-) diff --git a/lib/Slic3r/GUI.pm b/lib/Slic3r/GUI.pm index 52b28cd26..5159e95fc 100644 --- a/lib/Slic3r/GUI.pm +++ b/lib/Slic3r/GUI.pm @@ -32,7 +32,7 @@ our $have_LWP = eval "use LWP::UserAgent; 1"; use Wx 0.9901 qw(:bitmap :dialog :icon :id :misc :systemsettings :toplevelwindow :filedialog); -use Wx::Event qw(EVT_IDLE); +use Wx::Event qw(EVT_IDLE EVT_COMMAND); use base 'Wx::App'; use constant FILE_WILDCARDS => { @@ -67,6 +67,8 @@ $small_font->SetPointSize(11) if !&Wx::wxMSW; our $medium_font = Wx::SystemSettings::GetFont(wxSYS_DEFAULT_GUI_FONT); $medium_font->SetPointSize(12); +our $VERSION_CHECK_EVENT : shared = Wx::NewEventType; + sub OnInit { my ($self) = @_; @@ -140,6 +142,25 @@ sub OnInit { } }); + EVT_COMMAND($self, -1, $VERSION_CHECK_EVENT, sub { + my ($self, $event) = @_; + my ($success, $response, $manual_check) = @{$event->GetData}; + + if ($success) { + if ($response =~ /^obsolete ?= ?([a-z0-9.-]+,)*\Q$Slic3r::VERSION\E(?:,|$)/) { + my $res = Wx::MessageDialog->new(undef, "A new version is available. Do you want to open the Slic3r website now?", + 'Update', wxYES_NO | wxCANCEL | wxYES_DEFAULT | wxICON_INFORMATION | wxICON_ERROR)->ShowModal; + Wx::LaunchDefaultBrowser('http://slic3r.org/') if $res == wxID_YES; + } else { + Slic3r::GUI::show_info(undef, "You're using the latest version. No updates are available.") if $manual_check; + } + $Settings->{_}{last_version_check} = time(); + $self->save_settings; + } else { + Slic3r::GUI::show_error(undef, "Failed to check for updates. Try later.") if $manual_check; + } + }); + return 1; } @@ -230,13 +251,13 @@ sub presets { sub have_version_check { my ($self) = @_; - + $Slic3r::build = 1; # return an explicit 0 return ($Slic3r::have_threads && $Slic3r::build && $have_LWP) || 0; } sub check_version { - my ($self, %p) = @_; + my ($self, $manual_check) = @_; Slic3r::debugf "Checking for updates...\n"; @@ -245,19 +266,9 @@ sub check_version { my $ua = LWP::UserAgent->new; $ua->timeout(10); my $response = $ua->get('http://slic3r.org/updatecheck'); - if ($response->is_success) { - if ($response->decoded_content =~ /^obsolete ?= ?([a-z0-9.-]+,)*\Q$Slic3r::VERSION\E(?:,|$)/) { - my $res = Wx::MessageDialog->new(undef, "A new version is available. Do you want to open the Slic3r website now?", - 'Update', wxYES_NO | wxCANCEL | wxYES_DEFAULT | wxICON_INFORMATION | wxICON_ERROR)->ShowModal; - Wx::LaunchDefaultBrowser('http://slic3r.org/') if $res == wxID_YES; - } else { - Slic3r::GUI::show_info(undef, "You're using the latest version. No updates are available.") if $p{manual}; - } - $Settings->{_}{last_version_check} = time(); - $self->save_settings; - } else { - Slic3r::GUI::show_error(undef, "Failed to check for updates. Try later.") if $p{manual}; - } + Wx::PostEvent($self, Wx::PlThreadEvent->new(-1, $VERSION_CHECK_EVENT, + threads::shared::shared_clone([ $response->is_success, $response->decoded_content, $manual_check ]))); + Slic3r::thread_cleanup(); })->detach; } diff --git a/lib/Slic3r/GUI/MainFrame.pm b/lib/Slic3r/GUI/MainFrame.pm index 18c0a58b5..81031c5ad 100644 --- a/lib/Slic3r/GUI/MainFrame.pm +++ b/lib/Slic3r/GUI/MainFrame.pm @@ -247,7 +247,7 @@ sub _init_menubar { Wx::LaunchDefaultBrowser('http://slic3r.org/'); }); my $versioncheck = $self->_append_menu_item($helpMenu, "Check for &Updates...", 'Check for new Slic3r versions', sub { - wxTheApp->check_version(manual => 1); + wxTheApp->check_version(1); }); $versioncheck->Enable(wxTheApp->have_version_check); $self->_append_menu_item($helpMenu, "Slic3r &Manual", 'Open the Slic3r manual in your browser', sub {