Bugfix: early object destruction caused a segfault when splitting. Also fixed a memory leak and restore background processing when split only detected one part. #2466 #2398

This commit is contained in:
Alessandro Ranellucci 2014-12-30 13:16:28 +01:00
parent 494efe65b2
commit c4832c5342
3 changed files with 12 additions and 9 deletions

View file

@ -774,18 +774,20 @@ sub split_object {
my ($obj_idx, $current_object) = $self->selected_object; my ($obj_idx, $current_object) = $self->selected_object;
# we clone model object because split_object() adds the split volumes # we clone model object because split_object() adds the split volumes
# into the same model object, thus causing duplicated when we call load_model_objects() # into the same model object, thus causing duplicates when we call load_model_objects()
my $current_model_object = $self->{model}->clone->objects->[$obj_idx]; my $new_model = $self->{model}->clone; # store this before calling get_object()
my $current_model_object = $new_model->get_object($obj_idx);
if (@{$current_model_object->volumes} > 1) { if ($current_model_object->volumes_count > 1) {
Slic3r::GUI::warning_catcher($self)->("The selected object can't be split because it contains more than one volume/material."); Slic3r::GUI::warning_catcher($self)->("The selected object can't be split because it contains more than one volume/material.");
return; return;
} }
$self->stop_background_process; $self->pause_background_process;
my @model_objects = @{$current_model_object->split_object}; my @model_objects = @{$current_model_object->split_object};
if (@model_objects == 1) { if (@model_objects == 1) {
$self->resume_background_process;
Slic3r::GUI::warning_catcher($self)->("The selected object couldn't be split because it contains only one part."); Slic3r::GUI::warning_catcher($self)->("The selected object couldn't be split because it contains only one part.");
return; return;
} }

View file

@ -13,7 +13,7 @@ Model::Model(const Model &other)
// copy objects // copy objects
this->objects.reserve(other.objects.size()); this->objects.reserve(other.objects.size());
for (ModelObjectPtrs::const_iterator i = other.objects.begin(); i != other.objects.end(); ++i) for (ModelObjectPtrs::const_iterator i = other.objects.begin(); i != other.objects.end(); ++i)
this->add_object(**i); this->add_object(**i, true);
} }
Model& Model::operator= (Model other) Model& Model::operator= (Model other)
@ -618,6 +618,7 @@ ModelObject::split(ModelObjectPtrs* new_objects)
new_volume->material_id(volume->material_id()); new_volume->material_id(volume->material_id());
new_objects->push_back(new_object); new_objects->push_back(new_object);
delete *mesh;
} }
return; return;

View file

@ -42,9 +42,9 @@ template <class T>
class Ref { class Ref {
T* val; T* val;
public: public:
Ref() {} Ref() : val(NULL) {}
Ref(T* t) : val(t) {} Ref(T* t) : val(t) {}
operator T*() const {return val; } operator T*() const { return val; }
static const char* CLASS() { return ClassTraits<T>::name_ref; } static const char* CLASS() { return ClassTraits<T>::name_ref; }
}; };
@ -52,10 +52,10 @@ template <class T>
class Clone { class Clone {
T* val; T* val;
public: public:
Clone() : val() {} Clone() : val(NULL) {}
Clone(T* t) : val(new T(*t)) {} Clone(T* t) : val(new T(*t)) {}
Clone(const T& t) : val(new T(t)) {} Clone(const T& t) : val(new T(t)) {}
operator T*() const {return val; } operator T*() const { return val; }
static const char* CLASS() { return ClassTraits<T>::name; } static const char* CLASS() { return ClassTraits<T>::name; }
}; };
}; };