Fix Crash when delete model during simplification

This commit is contained in:
Filip Sykala 2021-09-01 20:19:55 +02:00
parent 25feacfd95
commit f6f70f6fd4
3 changed files with 32 additions and 11 deletions

View File

@ -7,7 +7,10 @@
using namespace Slic3r;
// Faster debug, comment when you want deep check
#ifndef NDEBUG
#define NDEBUG
#endif // !NDEBUG
// only private namespace not neccessary be in .hpp
namespace QuadricEdgeCollapse {
@ -105,10 +108,17 @@ namespace QuadricEdgeCollapse {
#endif /* NDEBUG */
// constants --> may be move to config
const int status_init_size = 10; // in percents
const uint32_t check_cancel_period = 16; // how many edge to reduce before call throw_on_cancel
const size_t max_triangle_count_for_one_vertex = 50;
} // namespace QuadricEdgeCollapse
// change speed of progress bargraph
const int status_init_size = 10; // in percents
// parts of init size
const int status_normal_size = 25;
const int status_sum_quadric = 25;
const int status_set_offsets = 10;
const int status_calc_errors = 30;
const int status_create_refs = 10;
} // namespace QuadricEdgeCollapse
using namespace QuadricEdgeCollapse;
@ -395,13 +405,6 @@ SymMat QuadricEdgeCollapse::create_quadric(const Triangle &t,
std::tuple<TriangleInfos, VertexInfos, EdgeInfos, Errors>
QuadricEdgeCollapse::init(const indexed_triangle_set &its, ThrowOnCancel& throw_on_cancel, StatusFn& status_fn)
{
// change speed of progress bargraph
const int status_normal_size = 25;
const int status_sum_quadric = 25;
const int status_set_offsets = 10;
const int status_calc_errors = 30;
const int status_create_refs = 10;
int status_offset = 0;
TriangleInfos t_infos(its.indices.size());
VertexInfos v_infos(its.vertices.size());

View File

@ -55,6 +55,7 @@ void GLGizmoSimplify::on_render_input_window(float x, float y, float bottom_limi
create_gui_cfg();
const Selection &selection = m_parent.get_selection();
int object_idx = selection.get_object_idx();
if (!is_selected_object(&object_idx)) return;
ModelObject *obj = wxGetApp().plater()->model().objects[object_idx];
ModelVolume *act_volume = obj->volumes.front();
@ -329,9 +330,9 @@ void GLGizmoSimplify::on_set_state()
{
// Closing gizmo. e.g. selecting another one
if (GLGizmoBase::m_state == GLGizmoBase::Off) {
// refuse outgoing during simlification
if (m_state != State::settings) {
// object is not selected when it is deleted(cancel and close gizmo)
if (m_state != State::settings && is_selected_object()) {
GLGizmoBase::m_state = GLGizmoBase::On;
auto notification_manager = wxGetApp().plater()->get_notification_manager();
notification_manager->push_notification(
@ -383,4 +384,20 @@ void GLGizmoSimplify::request_rerender() {
});
}
bool GLGizmoSimplify::is_selected_object(int *object_idx)
{
int index = (object_idx != nullptr) ? *object_idx :
m_parent.get_selection().get_object_idx();
// no selected object --> can appear after delete model
if (index < 0) {
switch (m_state) {
case State::settings: close(); break;
case State::canceling: break;
default: m_state = State::canceling;
}
return false;
}
return true;
}
} // namespace Slic3r::GUI

View File

@ -38,6 +38,7 @@ private:
void set_its(indexed_triangle_set &its);
void create_gui_cfg();
void request_rerender();
bool is_selected_object(int *object_idx = nullptr);
std::atomic_bool m_is_valid_result; // differ what to do in apply
std::atomic_bool m_exist_preview; // set when process end