From 7d21cf78c79010f892e2e3c71921f31b2d1353b1 Mon Sep 17 00:00:00 2001 From: Rodrigo Faselli <162915171+RF47@users.noreply.github.com> Date: Mon, 6 Apr 2026 03:06:48 -0300 Subject: [PATCH] =?UTF-8?q?=F0=9F=92=A5Fix=20crash=20when=20return=20from?= =?UTF-8?q?=20assembly=20mode=20linux=20(#13091)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * Fix return from assembly linux * Tie deferred callback to canvas lifetime and add shutdown guards Use m_canvas->CallAfter instead of wxGetApp().CallAfter to ensure the callback is only executed if the canvas is still alive. Add early returns if wxGetApp().is_closing() is true before accessing plater or the 3D canvas, reducing the risk of use-after-free during application shutdown. Addresses feedback regarding potential UI teardown race conditions. * copilot suggestion * Use local reference to wxGetApp() in Return button callback Replace multiple calls to wxGetApp() with a single local reference to improve readability and avoid redundant function calls. --- src/slic3r/GUI/GLCanvas3D.cpp | 24 ++++++++++++++++++++---- 1 file changed, 20 insertions(+), 4 deletions(-) diff --git a/src/slic3r/GUI/GLCanvas3D.cpp b/src/slic3r/GUI/GLCanvas3D.cpp index 334643a201..5e23a9d4ae 100644 --- a/src/slic3r/GUI/GLCanvas3D.cpp +++ b/src/slic3r/GUI/GLCanvas3D.cpp @@ -8480,11 +8480,27 @@ void GLCanvas3D::_render_return_toolbar() const ImVec2 margin = ImVec2(10.0f, 5.0f); if (ImGui::ImageTextButton(real_size,_utf8(L("Return")).c_str(), m_return_toolbar.get_return_texture_id(), button_icon_size, uv0, uv1, -1, bg_col, tint_col, margin)) { - if (m_canvas != nullptr) - wxPostEvent(m_canvas, SimpleEvent(EVT_GLVIEWTOOLBAR_3D)); const_cast(&m_gizmos)->reset_all_states(); - wxGetApp().plater()->get_view3D_canvas3D()->get_gizmos_manager().reset_all_states(); - wxGetApp().plater()->get_view3D_canvas3D()->reload_scene(true); + if (m_canvas != nullptr && !wxGetApp().is_closing()) { + m_canvas->CallAfter([]() { + auto& app = wxGetApp(); + if (app.is_closing()) + return; + + auto* plater = app.plater(); + if (plater == nullptr) + return; + + plater->select_view_3D("3D"); + + auto* view3d_canvas = plater->get_view3D_canvas3D(); + if (view3d_canvas == nullptr) + return; + + view3d_canvas->get_gizmos_manager().reset_all_states(); + view3d_canvas->reload_scene(true); + }); + } } ImGui::PopStyleColor(5); ImGui::PopStyleVar(1);