Skip to content

Port Snapmaker/OrcaSlicer #1004: stop backup thread wxPostEvent after shutdown - #475

Merged
aceRage merged 3 commits into
mainfrom
cursor/backup-callback-shutdown-race-05af
Oct 14, 2026
Merged

aceRage merged 3 commits into
mainfrom
cursor/backup-callback-shutdown-race-05af

Conversation

@aceRage

@aceRage aceRage commented Oct 13, 2026

Copy link
Copy Markdown
Owner

Description

Port of Snapmaker/OrcaSlicer #1004 onto Edge main.

Upstream head SHA ported: 4f3e868732eef29a6372ecef0888b53a41361515 (open, unmerged; may still change).
Edge branch head: 53d3288785cd050bea2f324c5a763384cacff3e7
Edge base: 83267707adc757e9ca1f2e1c946084768cef1d41 (main)

The backup worker (_BBS_Backup_Manager::operator()) used to snapshot m_post_callback under m_mutex, drop the lock for process_task(), then invoke the stale copy. MainFrame::shutdown() — on quit and on language-switch recreate — calls set_backup_callback(nullptr) and destroys the frame. If that lands in the unlocked window, the worker wxPostEvents into a destroyed MainFrame (Sentry SNAPMAKER_ORCA-7R / #7134242393, EXC_BAD_ACCESS).

This port:

  • Adds m_post_callback_mutex so callback swaps serialize against in-flight invokes (lock order m_mutex → m_post_callback_mutex).
  • Re-reads m_post_callback at fire time instead of using a stale local.
  • Catch-up: installing a non-null callback re-announces queued m_ui_tasks so language-switch recreate does not stall auto-backup (EVT_BACKUP_POST is edge-triggered on size()==1).

No public API change. process_ui_task()’s UI-thread callback(1) path is unchanged (same thread as the only writer).

Adapted, not cherry-picked: Edge bbs_3mf.cpp line numbers and Snapmaker extras around the worker are left as-is; only the callback swap/invoke path is touched.

Screenshots/Recordings/Graphs

N/A — shutdown race in the backup worker, no UI layout change.

Tests

Catch2 v2 in existing tests/libslic3r/test_3mf.cpp ([3mf][bbs-backup]). Upstream’s new test_bbs_backup.cpp + tests/libslic3r/CMakeLists.txt edit were not ported (Edge: existing test files only, no test CMake edits). Converted from Catch2 v3 (catch_test_macros.hpp) to v2 (catch.hpp).

libslic3r_tests "[bbs-backup]"

This cloud VM has no slicer deps/libslic3r_tests binary, so the case was not executed here. Edge CI is the gate.

Manual smoke (owed on a built app)

  • Quit while a backup cycle is in flight (5 trials): no hang, no crash, process exits clean.
  • Language switch (recreate GUI) while a backup is queued: auto-backup still fires after the new MainFrame is up; no stall until exit.
  • Idle backup interval still writes .3mf under the project backup path after a period of edits.
Open in Web Open in Cursor 

cursoragent and others added 3 commits October 13, 2026 15:10
…ent after shutdown

Serialize m_post_callback swaps against the worker's in-flight invoke so
set_backup_callback(nullptr) cannot leave a stale MainFrame lambda to
wxPostEvent into a destroyed frame. Re-announce queued ui tasks when a
fresh callback is installed so language-switch recreate does not stall
auto-backup. Coverage lives in existing test_3mf.cpp (Catch2 v2).

Co-authored-by: aceRage <aceRage@users.noreply.github.com>
Resolve tests/libslic3r/test_3mf.cpp: keep both appended test blocks.

Deft
The backup manager is a process-wide singleton, so leftover ui tasks can make
the first announcement arrive before the test's own Backup task is queued.
Consume until the backup response (action 1) is seen instead of assuming one pass.

Deft
@aceRage
aceRage marked this pull request as ready for review October 14, 2026 09:17
@aceRage
aceRage merged commit aa8996e into main Oct 14, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants