From f5080ea7f56806be7c39a34bde8ec64c378ceac7 Mon Sep 17 00:00:00 2001 From: Vojtech Kral Date: Tue, 27 Nov 2018 16:55:54 +0100 Subject: [PATCH] Fix re-entrant render() calls, add an assert to enforce --- src/slic3r/GUI/GLCanvas3D.cpp | 8 ++++++++ src/slic3r/GUI/GLCanvas3D.hpp | 1 + src/slic3r/GUI/GUI_ObjectList.cpp | 6 +++--- 3 files changed, 12 insertions(+), 3 deletions(-) diff --git a/src/slic3r/GUI/GLCanvas3D.cpp b/src/slic3r/GUI/GLCanvas3D.cpp index 3d461792e..3b40979f3 100644 --- a/src/slic3r/GUI/GLCanvas3D.cpp +++ b/src/slic3r/GUI/GLCanvas3D.cpp @@ -7,6 +7,7 @@ #include "libslic3r/PrintConfig.hpp" #include "libslic3r/GCode/PreviewData.hpp" #include "libslic3r/Geometry.hpp" +#include "libslic3r/Utils.hpp" #include "slic3r/GUI/3DScene.hpp" #include "slic3r/GUI/BackgroundSlicingProcess.hpp" #include "slic3r/GUI/GLShader.hpp" @@ -26,6 +27,7 @@ #include #include #include +#include // Print now includes tbb, and tbb includes Windows. This breaks compilation of wxWidgets if included before wx. #include "libslic3r/Print.hpp" @@ -3311,6 +3313,7 @@ wxDEFINE_EVENT(EVT_GLCANVAS_MOUSE_DRAGGING_FINISHED, SimpleEvent); GLCanvas3D::GLCanvas3D(wxGLCanvas* canvas) : m_canvas(canvas) , m_context(nullptr) + , m_in_render(false) , m_toolbar(*this) , m_use_clipping_planes(false) , m_config(nullptr) @@ -3737,6 +3740,11 @@ bool GLCanvas3D::gizmo_reset_rect_contains(const GLCanvas3D& canvas, float x, fl void GLCanvas3D::render() { + wxCHECK_RET(!m_in_render, "GLCanvas3D::render() called recursively"); + m_in_render = true; + Slic3r::ScopeGuard in_render_guard([this]() { m_in_render = false; }); + (void)in_render_guard; + if (m_canvas == nullptr) return; diff --git a/src/slic3r/GUI/GLCanvas3D.hpp b/src/slic3r/GUI/GLCanvas3D.hpp index 4ecb9ea92..9762539af 100644 --- a/src/slic3r/GUI/GLCanvas3D.hpp +++ b/src/slic3r/GUI/GLCanvas3D.hpp @@ -717,6 +717,7 @@ private: wxGLCanvas* m_canvas; wxGLContext* m_context; + bool m_in_render; LegendTexture m_legend_texture; WarningTexture m_warning_texture; wxTimer m_timer; diff --git a/src/slic3r/GUI/GUI_ObjectList.cpp b/src/slic3r/GUI/GUI_ObjectList.cpp index 7ae569c99..23da410e9 100644 --- a/src/slic3r/GUI/GUI_ObjectList.cpp +++ b/src/slic3r/GUI/GUI_ObjectList.cpp @@ -1361,7 +1361,7 @@ void ObjectList::update_selections_on_canvas() const int sel_cnt = GetSelectedItemsCount(); if (sel_cnt == 0) { selection.clear(); - wxGetApp().plater()->canvas3D()->render(); + wxGetApp().plater()->canvas3D()->set_as_dirty(); return; } @@ -1391,7 +1391,7 @@ void ObjectList::update_selections_on_canvas() else add_to_selection(item, selection, true); - wxGetApp().plater()->canvas3D()->render(); + wxGetApp().plater()->canvas3D()->set_as_dirty(); return; } @@ -1402,7 +1402,7 @@ void ObjectList::update_selections_on_canvas() for (auto item: sels) add_to_selection(item, selection, false); - wxGetApp().plater()->canvas3D()->render(); + wxGetApp().plater()->canvas3D()->set_as_dirty(); } void ObjectList::select_item(const wxDataViewItem& item)