From 5409c27852374032271490b98eb4cc768c5b4f89 Mon Sep 17 00:00:00 2001 From: Alessandro Ranellucci Date: Sun, 7 Jul 2013 18:43:04 +0200 Subject: [PATCH] Partial GUI compatibility with XS data --- lib/Slic3r.pm | 9 ++++++++- lib/Slic3r/ExPolygon.pm | 7 +------ lib/Slic3r/GUI/Plater.pm | 4 ++-- lib/Slic3r/Polyline.pm | 5 ----- 4 files changed, 11 insertions(+), 14 deletions(-) diff --git a/lib/Slic3r.pm b/lib/Slic3r.pm index a3761ac6b..00d19713a 100644 --- a/lib/Slic3r.pm +++ b/lib/Slic3r.pm @@ -86,7 +86,14 @@ sub parallelize { my $q = Thread::Queue->new; $q->enqueue(@items, (map undef, 1..$Config->threads)); - my $thread_cb = sub { $params{thread_cb}->($q) }; + my $thread_cb = sub { + # prevent destruction of shared objects + no warnings 'redefine'; + *Slic3r::ExPolygon::XS::DESTROY = sub {}; + + return $params{thread_cb}->($q); + }; + @_ = (); foreach my $th (map threads->create($thread_cb), 1..$Config->threads) { $params{collect_cb}->($th->join); diff --git a/lib/Slic3r/ExPolygon.pm b/lib/Slic3r/ExPolygon.pm index 3cb7c8ee1..19b3a90b6 100644 --- a/lib/Slic3r/ExPolygon.pm +++ b/lib/Slic3r/ExPolygon.pm @@ -35,11 +35,6 @@ sub clone { # no-op for legacy with ::XS sub arrayref { $_[0] } -sub threadsafe_clone { - my $self = shift; - return (ref $self)->new(map $_->threadsafe_clone, @$self); -} - sub contour { my $self = shift; return $self->[0]; @@ -314,7 +309,7 @@ has 'expolygons' => (is => 'ro', default => sub { [] }); sub clone { my $self = shift; return (ref $self)->new( - expolygons => [ map $_->threadsafe_clone, @{$self->expolygons} ], + expolygons => [ map $_->clone, @{$self->expolygons} ], ); } diff --git a/lib/Slic3r/GUI/Plater.pm b/lib/Slic3r/GUI/Plater.pm index d9ac19c5b..dee592153 100644 --- a/lib/Slic3r/GUI/Plater.pm +++ b/lib/Slic3r/GUI/Plater.pm @@ -921,7 +921,7 @@ sub mouse_event { $parent->selection_changed(0); for my $preview (@{$parent->{object_previews}}) { my ($obj_idx, $instance_idx, $thumbnail) = @$preview; - if (first { $_->contour->encloses_point($pos) } @{$thumbnail->expolygons}) { + if (defined first { $_->contour->encloses_point($pos) } @{$thumbnail->expolygons}) { $parent->{selected_objects} = [ [$obj_idx, $instance_idx] ]; $parent->{list}->Select($obj_idx, 1); $parent->selection_changed(1); @@ -951,7 +951,7 @@ sub mouse_event { } elsif ($event->Moving) { my $cursor = wxSTANDARD_CURSOR; for my $preview (@{$parent->{object_previews}}) { - if (first { $_->contour->encloses_point($pos) } @{ $preview->[2]->expolygons }) { + if (defined first { $_->contour->encloses_point($pos) } @{ $preview->[2]->expolygons }) { $cursor = Wx::Cursor->new(wxCURSOR_HAND); last; } diff --git a/lib/Slic3r/Polyline.pm b/lib/Slic3r/Polyline.pm index d63451a08..b979abad0 100644 --- a/lib/Slic3r/Polyline.pm +++ b/lib/Slic3r/Polyline.pm @@ -22,11 +22,6 @@ sub clone { Storable::dclone($_[0]) } -sub threadsafe_clone { - my $self = shift; - return (ref $self)->new(map $_->threadsafe_clone, @$self); -} - sub serialize { my $self = shift; return pack 'l*', map @$_, @$self;