From a6483e79b241ce2b9ee79841913422f7a5a726dc Mon Sep 17 00:00:00 2001 From: Lam Wei Lun Date: Mon, 31 Aug 2026 14:50:15 +0800 Subject: [PATCH] Fix ImGui crash --- src/slic3r/GUI/NotificationManager.cpp | 6 +++++- src/slic3r/GUI/NotificationManager.hpp | 5 +++++ 2 files changed, 10 insertions(+), 1 deletion(-) diff --git a/src/slic3r/GUI/NotificationManager.cpp b/src/slic3r/GUI/NotificationManager.cpp index bfb9f50130..044771bf7c 100644 --- a/src/slic3r/GUI/NotificationManager.cpp +++ b/src/slic3r/GUI/NotificationManager.cpp @@ -3083,7 +3083,7 @@ bool NotificationManager::push_notification_data(std::unique_ptractivate_existing(notification.get())) { - if (m_initialized) { // ignore update action - it cant be initialized if canvas and imgui context is not ready + if (m_initialized && m_imgui_ready) { if (notification->get_type() == NotificationType::SlicingWarning) { m_pop_notifications.back()->append(notification->get_data().ori_text); } else { @@ -3129,6 +3129,10 @@ void NotificationManager::stop_delayed_notifications_of_type(const NotificationT void NotificationManager::render_notifications(GLCanvas3D &canvas, float overlay_width, float bottom_margin, float right_margin) { + // Notifications render inside an ImGui frame, so the font atlas is built from this point on + // and pushed notifications may safely measure their text. + m_imgui_ready = true; + sort_notifications(); float bottom_up_last_y = bottom_margin; // ORCA dont scale margins diff --git a/src/slic3r/GUI/NotificationManager.hpp b/src/slic3r/GUI/NotificationManager.hpp index d7a5d49977..55d10dd95c 100644 --- a/src/slic3r/GUI/NotificationManager.hpp +++ b/src/slic3r/GUI/NotificationManager.hpp @@ -1054,6 +1054,11 @@ private: bool m_is_dark = false; // set by init(), until false notifications are only added not updated and frame is not requested after push bool m_initialized{ false }; + // set by render_notifications() on the first rendered frame. m_initialized only proves the + // manager exists, not that the ImGui context can measure text: the font atlas is built lazily + // in ImGuiWrapper::new_frame() on the first GL render, so updating a notification before that + // (PopNotification::init -> count_spaces -> ImGui::CalcTextSize) dereferences a null font. + bool m_imgui_ready{ false }; // Target for wxWidgets events sent by clicking on the hyperlink available at some notifications. wxEvtHandler* m_evt_handler; // Cache of IDs to identify and reuse ImGUI windows.