diff --git a/src/slic3r/GUI/GUI_App.cpp b/src/slic3r/GUI/GUI_App.cpp index 3728481aa4..bd1f22d754 100644 --- a/src/slic3r/GUI/GUI_App.cpp +++ b/src/slic3r/GUI/GUI_App.cpp @@ -8017,6 +8017,15 @@ void GUI_App::start_sync_user_preset(bool with_progress_dlg) m_sync_update_thread = Slic3r::create_thread( [this, progressFn, cancelFn, finishFn, t = std::weak_ptr(m_user_sync_token)] { + // NotificationManager is not thread safe and is destroyed before this thread is joined + const auto notify = [this, t](const std::string& text) { + CallAfter([this, t, text] { + if (t.expired() || is_closing()) + return; + plater()->get_notification_manager()->push_notification(NotificationType::CustomNotification, + NotificationManager::NotificationLevel::RegularNotificationLevel, text); + }); + }; // finishFn tears down the progress dialog (and clears the re-entrancy guard), so it // must run on every exit path — otherwise an early bail-out would leak the modal // dialog and leave the guard stuck, blocking all later manual syncs. @@ -8167,16 +8176,14 @@ void GUI_App::start_sync_user_preset(bool with_progress_dlg) { for(auto& n : not_found) { - std::string text = format(_L("Bundle %s is no longer available."), n); - wxGetApp().plater()->get_notification_manager()->push_notification(NotificationType::CustomNotification,NotificationManager::NotificationLevel::RegularNotificationLevel,text); + notify(format(_L("Bundle %s is no longer available."), n)); } } if(!unauthorized.empty()) { for(auto& i : unauthorized) { - std::string text = format(_L("Bundle %s access is unauthorized."), i); - wxGetApp().plater()->get_notification_manager()->push_notification(NotificationType::CustomNotification,NotificationManager::NotificationLevel::RegularNotificationLevel,text); + notify(format(_L("Bundle %s access is unauthorized."), i)); preset_bundle->bundles.ReadLock(); if(preset_bundle->bundles.m_bundles.find(i) != preset_bundle->bundles.m_bundles.end()) { @@ -8188,6 +8195,9 @@ void GUI_App::start_sync_user_preset(bool with_progress_dlg) // Iterate over the bundles, and update/create for (const auto& bundle_entry : bundles_to_sync) { + // a partial bundles_synced would delete the unvisited bundles below + if (t.expired() || is_closing()) + return; bundles_synced.insert(bundle_entry.first); // Sync each bundle individually // if(!preset_bundle->bundles.pauseReads.load()) // if pause is true we will skip updating this frame altogether @@ -8206,12 +8216,7 @@ void GUI_App::start_sync_user_preset(bool with_progress_dlg) } if (update_available) { - wxGetApp() - .plater() - ->get_notification_manager() - ->push_notification(NotificationType::CustomNotification, - NotificationManager::NotificationLevel::RegularNotificationLevel, _u8L("There is an update available. Open the preset bundle dialog to update it.")); - + notify(_u8L("There is an update available. Open the preset bundle dialog to update it.")); update_available = false; } @@ -8252,8 +8257,7 @@ void GUI_App::start_sync_user_preset(bool with_progress_dlg) preset_bundle->bundles.m_bundles.erase(bundle.id); preset_bundle->bundles.WriteUnlock(); - std::string text = format(_L("%s has been removed."), bundle.name); - wxGetApp().plater()->get_notification_manager()->push_notification(NotificationType::CustomNotification,NotificationManager::NotificationLevel::RegularNotificationLevel,text); + notify(format(_L("%s has been removed."), bundle.name)); has_deletion = true; }