Add thread cleanup to avoid double destruction of shared XS data
This commit is contained in:
parent
3037b42b47
commit
8d171a297e
2 changed files with 19 additions and 5 deletions
|
@ -87,11 +87,9 @@ sub parallelize {
|
||||||
$q->enqueue(@items, (map undef, 1..$Config->threads));
|
$q->enqueue(@items, (map undef, 1..$Config->threads));
|
||||||
|
|
||||||
my $thread_cb = sub {
|
my $thread_cb = sub {
|
||||||
# prevent destruction of shared objects
|
my $result = $params{thread_cb}->($q);
|
||||||
no warnings 'redefine';
|
Slic3r::thread_cleanup();
|
||||||
*Slic3r::ExPolygon::XS::DESTROY = sub {};
|
return $result;
|
||||||
|
|
||||||
return $params{thread_cb}->($q);
|
|
||||||
};
|
};
|
||||||
|
|
||||||
@_ = ();
|
@_ = ();
|
||||||
|
@ -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 {
|
sub encode_path {
|
||||||
my ($filename) = @_;
|
my ($filename) = @_;
|
||||||
return encode('locale_fs', $filename);
|
return encode('locale_fs', $filename);
|
||||||
|
|
|
@ -570,6 +570,7 @@ sub export_gcode {
|
||||||
});
|
});
|
||||||
},
|
},
|
||||||
);
|
);
|
||||||
|
Slic3r::thread_cleanup();
|
||||||
});
|
});
|
||||||
$self->statusbar->SetCancelCallback(sub {
|
$self->statusbar->SetCancelCallback(sub {
|
||||||
$self->{export_thread}->kill('KILL')->join;
|
$self->{export_thread}->kill('KILL')->join;
|
||||||
|
@ -744,6 +745,8 @@ sub make_thumbnail {
|
||||||
} else {
|
} else {
|
||||||
$self->on_thumbnail_made($obj_idx);
|
$self->on_thumbnail_made($obj_idx);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Slic3r::thread_cleanup() if $Slic3r::have_threads;
|
||||||
};
|
};
|
||||||
|
|
||||||
@_ = ();
|
@_ = ();
|
||||||
|
|
Loading…
Reference in a new issue