From e50bbc0245677514eb14e0f426ac7d1d20a28d54 Mon Sep 17 00:00:00 2001 From: Alessandro Ranellucci <aar@cpan.org> Date: Mon, 16 Nov 2015 12:50:16 +0100 Subject: [PATCH] Don't crash when no serial ports are available on Windows --- lib/Slic3r/GUI.pm | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/lib/Slic3r/GUI.pm b/lib/Slic3r/GUI.pm index 782645f83..2ad56e8ca 100644 --- a/lib/Slic3r/GUI.pm +++ b/lib/Slic3r/GUI.pm @@ -322,9 +322,13 @@ sub scan_serial_ports { # Windows if (eval "use Win32::TieRegistry; 1") { my $ts = Win32::TieRegistry->new("HKEY_LOCAL_MACHINE\\HARDWARE\\DEVICEMAP\\SERIALCOMM", - { Access => Win32::TieRegistry::KEY_READ() }); - $ts->Tie(\my %reg); - push @ports, sort values %reg; + { Access => 'KEY_READ' }); + if ($ts) { + # when no serial ports are available, the registry key doesn't exist and + # TieRegistry->new returns undef + $ts->Tie(\my %reg); + push @ports, sort values %reg; + } } } else { # UNIX and OS X