mirror of
https://github.com/OrcaSlicer/OrcaSlicer.git
synced 2026-12-06 03:38:01 -05:00
Fix crash at exit from the preset sync thread (#16948)
The preset sync thread pushed bundle notifications to the notification manager directly from the thread. At exit the Plater is destroyed before OnExit() joins the thread, so a pass still running could crash in push_notification_data().
The notifications are now pushed on the GUI thread with CallAfter() and dropped once the app is closing or the sync is stopped. The bundle loop also returns as soon as the sync is stopped, so the thread exits quickly and does not delete the subscribed bundles it did not reach.
(cherry picked from commit e410cf3656)
This commit is contained in:
1 parent
fe8c44b7bb
commit
7d51b5e9b3
1 file changed
+16
-12
+16
-12
@@ -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<int>(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;
|
||||
}
|
||||
|
||||
|
||||
Reference in new issue
Block a user