From fa18a7786e502aa3a0b60f53fe68955e331c967e Mon Sep 17 00:00:00 2001 From: yw4z Date: Sun, 29 Nov 2026 16:27:49 +0300 Subject: [PATCH] Windows: stop WebView2 / Crashpad processes piling up during debugging (#16784) * Update OrcaSlicer_app_msvc.cpp * Update src/OrcaSlicer_app_msvc.cpp Co-authored-by: HanifKoh <76276251+HanifKoh@users.noreply.github.com> * Update src/OrcaSlicer_app_msvc.cpp Co-authored-by: HanifKoh <76276251+HanifKoh@users.noreply.github.com> --------- Co-authored-by: HanifKoh <76276251+HanifKoh@users.noreply.github.com> --- src/OrcaSlicer_app_msvc.cpp | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) diff --git a/src/OrcaSlicer_app_msvc.cpp b/src/OrcaSlicer_app_msvc.cpp index 14295b27c3..e35577c13c 100644 --- a/src/OrcaSlicer_app_msvc.cpp +++ b/src/OrcaSlicer_app_msvc.cpp @@ -205,6 +205,28 @@ protected: bool OpenGLVersionCheck::message_pump_exit = false; #endif /* SLIC3R_GUI */ +// Under a debugger (e.g. Visual Studio), tie child processes (WebView2, Crashpad) to our lifetime +// so "Stop Debugging" doesn't leave them running. +static void bind_child_processes_to_lifetime_when_debugging() +{ + if (!::IsDebuggerPresent()) + return; + + HANDLE job = ::CreateJobObjectW(nullptr, nullptr); + if (job == nullptr) + return; + + JOBOBJECT_EXTENDED_LIMIT_INFORMATION info = {}; + info.BasicLimitInformation.LimitFlags = JOB_OBJECT_LIMIT_KILL_ON_JOB_CLOSE; + + if (!::SetInformationJobObject(job, JobObjectExtendedLimitInformation, &info, sizeof(info)) || + !::AssignProcessToJobObject(job, ::GetCurrentProcess())) { + ::CloseHandle(job); + return; + } + // The job handle is intentionally never closed. The OS closes it when this process terminates. +} + extern "C" { typedef int (__stdcall *Slic3rMainFunc)(int argc, wchar_t **argv); Slic3rMainFunc orcaslicer_main = nullptr; @@ -225,6 +247,8 @@ int wmain(int argc, wchar_t **argv) // the application will be killed even if "Ignore" button is pressed. _set_error_mode(_OUT_TO_MSGBOX); + bind_child_processes_to_lifetime_when_debugging(); + std::vector argv_extended; argv_extended.emplace_back(argv[0]);