Add thread cleanup to avoid double destruction of shared XS data
This commit is contained in:
parent
3037b42b47
commit
8d171a297e
@ -87,11 +87,9 @@ sub parallelize {
|
||||
$q->enqueue(@items, (map undef, 1..$Config->threads));
|
||||
|
||||
my $thread_cb = sub {
|
||||
# prevent destruction of shared objects
|
||||
no warnings 'redefine';
|
||||
*Slic3r::ExPolygon::XS::DESTROY = sub {};
|
||||
|
||||
return $params{thread_cb}->($q);
|
||||
my $result = $params{thread_cb}->($q);
|
||||
Slic3r::thread_cleanup();
|
||||
return $result;
|
||||
};
|
||||
|
||||
@_ = ();
|
||||
@ -103,6 +101,19 @@ sub parallelize {
|
||||
}
|
||||
}
|
||||
|
||||
# call this at the very end of each thread (except the main one)
|
||||
# so that it does not try to free existing objects.
|
||||
# at that stage, existing objects are only those that we
|
||||
# inherited at the thread creation (thus shared) and those
|
||||
# that we are returning: destruction will be handled by the
|
||||
# main thread in both cases.
|
||||
sub thread_cleanup {
|
||||
# prevent destruction of shared objects
|
||||
no warnings 'redefine';
|
||||
*Slic3r::ExPolygon::XS::DESTROY = sub {};
|
||||
*Slic3r::Point::XS::DESTROY = sub {};
|
||||
}
|
||||
|
||||
sub encode_path {
|
||||
my ($filename) = @_;
|
||||
return encode('locale_fs', $filename);
|
||||
|
@ -570,6 +570,7 @@ sub export_gcode {
|
||||
});
|
||||
},
|
||||
);
|
||||
Slic3r::thread_cleanup();
|
||||
});
|
||||
$self->statusbar->SetCancelCallback(sub {
|
||||
$self->{export_thread}->kill('KILL')->join;
|
||||
@ -744,6 +745,8 @@ sub make_thumbnail {
|
||||
} else {
|
||||
$self->on_thumbnail_made($obj_idx);
|
||||
}
|
||||
|
||||
Slic3r::thread_cleanup() if $Slic3r::have_threads;
|
||||
};
|
||||
|
||||
@_ = ();
|
||||
|
Loading…
Reference in New Issue
Block a user