Skip to content

fix: thread-safety fixes for log_version_info and flush_logs, Linux locale init#336

Open
SukiSunYuhang wants to merge 4 commits into
Snapmaker:feature_update_logfrom
SukiSunYuhang:feature_update_log
Open

fix: thread-safety fixes for log_version_info and flush_logs, Linux locale init#336
SukiSunYuhang wants to merge 4 commits into
Snapmaker:feature_update_logfrom
SukiSunYuhang:feature_update_log

Conversation

@SukiSunYuhang
Copy link
Copy Markdown

Description

Thread-safety for log_version_info: Cache OS description with std::call_once to prevent wxGetLinuxDistributionInfo/wxGetOsDescription from being called on background threads. These wx APIs are not thread-safe on Linux (GTK), and were being triggered via generic_exception_handle → OnExceptionInMainLoop from BackgroundSlicingProcess worker threads, causing crashes when using the network test dialog.
Mutex for flush_logs: Add a static mutex to protect the global g_log_sink shared_ptr access against concurrent flush calls from multiple threads.
Linux locale initialization: Call std::setlocale(LC_ALL, "") early in on_init_inner to fix garbled Chinese text and GTK file dialog crashes on Linux.
Anti-reentrancy for network test: Add atomic flag to NetworkTestDialog::start_all_job to prevent re-entrant test launches from rapid button clicks.

Files changed

src/libslic3r/utils.cpp — add mutex to flush_logs()
src/slic3r/GUI/GUI_App.cpp — cache OS info in log_version_info() + Linux locale init
src/slic3r/GUI/NetworkTestDialog.cpp — anti-reentrancy in start_all_job()
src/slic3r/GUI/NetworkTestDialog.hpp — new m_all_testing atomic flag

…ocale init

- log_version_info: cache OS description with std::call_once to prevent
  wxGetLinuxDistributionInfo/wxGetOsDescription from being called on
  background threads (GTK/wx APIs are not thread-safe on Linux).
  Previously, generic_exception_handle -> OnExceptionInMainLoop could
  trigger these calls from BackgroundSlicingProcess worker threads,
  causing crashes when opening network test dialog on Linux.

- flush_logs: add mutex to protect g_log_sink shared_ptr access
  against concurrent flush calls from multiple threads.

- on_init_inner: call std::setlocale(LC_ALL, "") on Linux early in
  startup to fix garbled Chinese text and GTK file dialog crashes.

- NetworkTestDialog::start_all_job: add atomic flag to prevent
  re-entrant test launches from rapid button clicks.
@SukiSunYuhang SukiSunYuhang requested a review from LiuLikeQian May 20, 2026 04:14
…tLocalArea, getLanguage

All four functions had empty #else (Linux) branches, causing them to always
return empty strings on Linux. Added get_linux_config_dir() helper that
resolves $XDG_CONFIG_HOME/Snapmaker_Orca or ~/.config/Snapmaker_Orca,
consistent with how data_dir() is determined on Linux.
… detach and let the m_closing checkpoint handle the rest.
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.

1 participant