Repository navigation
Conversation
The backup thread copied m_post_callback, ran the backup without the lock and then called the copy. MainFrame::shutdown() clears the callback before the frame is destroyed, but a copy taken earlier still posted an event to the destroyed frame, which crashed the app on exit (SIGSEGV in the backup thread). Call m_post_callback as it is when the lock is taken again; once shutdown() has cleared it, it is no longer called. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Description
Summary
Closing CrealityPrint sometimes crashed it with
SIGSEGVin the auto-backup thread. The window was already gone, so users only notice it from the crash report or core dump. The backup thread called a copy of the post callback that it took before running the backup, afterMainFrame::shutdown()had already cleared the callback and the frame had been destroyed. This PR makes the thread call the callback as it is at the moment of the call.One file is changed:
src/libslic3r/Format/bbs_3mf.cpp(+5 / −3 lines). The code is shared by all platforms; the crash was seen on Linux.Symptom
Close CrealityPrint, especially shortly after changing the project, when an auto-backup is due. Sometimes
systemd-coredumprecords aSIGSEGVfor/app/CrealityPrint, in a secondary thread:A second occurrence, under gdb, was a
SIGSEGVat0x20in a secondary thread right after the window was closed. gdb did not record a backtrace for it, so it is likely, but not confirmed, to be the same thread.Root cause
MainFrameregisters a backup callback in its constructor (MainFrame.cpp,Slic3r::set_backup_callback([this](int action) { ... })). Foraction == 0it callswxPostEvent(this, ...).MainFrame::shutdown()clears it withSlic3r::set_backup_callback(nullptr)before the frame is destroyed.set_post_callback()takes the backup manager's mutex.The backup thread loop (
_BBS_Backup_Manager::operator()) did:If the app is closed while
process_task()runs,shutdown()clearsm_post_callback, but the thread still calls the copy taken before it. The lambda then posts an event to the destroyedMainFrame, and the call through the freed object lands at an invalid address (0x0in the backtrace above).Fix
Call
m_post_callbackas it is when the thread takes the lock again, instead of the copy:set_post_callback()takes the same mutex. Onceshutdown()has cleared the callback, it is never called again.shutdown()runs,set_post_callback(nullptr)waits for it. The frame still exists at that point, becauseshutdown()runs before it is destroyed.action == 0the callback only callswxPostEvent(), which does not take the backup mutex, and the thread already held the mutex when it called the copy before.BackupUI task (process_ui_task()), which takes its own copy before calling withaction == 1, runs on the UI thread and is not changed.Testing
Tested on Fedora 45, GNOME 50, Wayland, Flatpak (GNOME 50 runtime, LLVM 21), on the 7.3.2 sources; the backup loop is identical on the current
master.0x20jump under gdb.The crash depends on timing (closing while a backup runs), so the absence of crashes is good evidence but not proof. The reasoning above does not depend on timing.
🤖 Generated with Claude Code