FIX: fix the crash issue #1944 caused by wronog thread name in some

corner cases

this patch is cherry-picked from PrusaSlicer's 84722876012ca310e29b291e10fef9d18ae26cea
thanks to 'Vojtech Bubnik' for the fix

Implementing a test whether the current thread is the main (UI) thread
and using it on AppConfig::save() to assert if save is called
from a worker thread.
The old assert was using thread names, which did not always work
on Windows.
Fixes #7839 #9178 #9370 #9420
This commit is contained in:
Vojtech Bubnik 2023-02-07 16:17:26 +01:00 committed by Lane.Wei
parent 12eec78d1d
commit 153c9517ce
4 changed files with 33 additions and 14 deletions

View file

@ -593,14 +593,8 @@ std::string AppConfig::load()
void AppConfig::save()
{
{
// Returns "undefined" if the thread naming functionality is not supported by the operating system.
std::optional<std::string> current_thread_name = get_current_thread_name();
if (current_thread_name && *current_thread_name != "bambustu_main" && *current_thread_name != "main") {
BOOST_LOG_TRIVIAL(error) << __FUNCTION__<<", current_thread_name is " << *current_thread_name;
throw CriticalException("Calling AppConfig::save() from a worker thread, thread name: " + *current_thread_name);
}
}
if (! is_main_thread_active())
throw CriticalException("Calling AppConfig::save() from a worker thread!");
// The config is first written to a file with a PID suffix and then moved
// to avoid race conditions with multiple instances of Slic3r
@ -872,12 +866,8 @@ std::string AppConfig::load()
void AppConfig::save()
{
{
// Returns "undefined" if the thread naming functionality is not supported by the operating system.
std::optional<std::string> current_thread_name = get_current_thread_name();
if (current_thread_name && *current_thread_name != "bambustu_main")
throw CriticalException("Calling AppConfig::save() from a worker thread!");
}
if (! is_main_thread_active())
throw CriticalException("Calling AppConfig::save() from a worker thread!");
// The config is first written to a file with a PID suffix and then moved
// to avoid race conditions with multiple instances of Slic3r