Просмотр исходного кода

Partial GUI compatibility with XS data

Alessandro Ranellucci 11 лет назад
Родитель
Сommit
5409c27852
4 измененных файлов с 11 добавлено и 14 удалено
  1. 8 1
      lib/Slic3r.pm
  2. 1 6
      lib/Slic3r/ExPolygon.pm
  3. 2 2
      lib/Slic3r/GUI/Plater.pm
  4. 0 5
      lib/Slic3r/Polyline.pm

+ 8 - 1
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);

+ 1 - 6
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} ],
     );
 }
 

+ 2 - 2
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;
             }

+ 0 - 5
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;