From 9cb538956dbd106638cd79698f8611891ad175ad Mon Sep 17 00:00:00 2001 From: alves Date: Wed, 3 Dec 2025 09:27:09 +0800 Subject: [PATCH 01/22] feature add sentry for soft catch dmp --- .github/workflows/build_deps.yml | 11 ++ .github/workflows/build_orca.yml | 17 ++ .github/workflows/sentry_cli.yml | 57 +++++++ CMakeLists.txt | 27 ++++ deps/CMakeLists.txt | 7 + deps/Sentry/Sentry.cmake | 63 ++++++++ src/CMakeLists.txt | 2 +- src/Snapmaker_Orca.cpp | 64 -------- src/Snapmaker_Orca_app_msvc.cpp | 268 ++++++++++++++++++++++--------- src/dev-utils/BaseException.h | 2 - src/libslic3r/PresetBundle.cpp | 2 +- src/slic3r/GUI/Preferences.cpp | 5 + 12 files changed, 377 insertions(+), 148 deletions(-) create mode 100644 .github/workflows/sentry_cli.yml create mode 100644 deps/Sentry/Sentry.cmake diff --git a/.github/workflows/build_deps.yml b/.github/workflows/build_deps.yml index a33b234f2e..6cd71744b1 100644 --- a/.github/workflows/build_deps.yml +++ b/.github/workflows/build_deps.yml @@ -150,3 +150,14 @@ jobs: os: ${{ inputs.os }} arch: ${{ inputs.arch }} secrets: inherit + + upload_symbols: + name: Upload Debug Symbols to Sentry + needs: [build_orca] + if: ${{ !cancelled() && needs.build_orca.result == 'success' }} + uses: ./.github/workflows/sentry_cli.yml + with: + os: ${{ inputs.os }} + pdb-artifact-name: PDB + release: ${{ github.sha }} + secrets: inherit \ No newline at end of file diff --git a/.github/workflows/build_orca.yml b/.github/workflows/build_orca.yml index 0fcf640657..7f6fcd4eef 100644 --- a/.github/workflows/build_orca.yml +++ b/.github/workflows/build_orca.yml @@ -18,6 +18,8 @@ jobs: build_orca: name: Build Snapmaker_Orca runs-on: ${{ inputs.os }} + outputs: + release: ${{ steps.set_release.outputs.release || steps.set_release_win.outputs.release }} env: date: ver: @@ -77,6 +79,21 @@ jobs: echo "date: ${{ env.date }} version: ${{ env.ver }}" shell: pwsh + - name: Set release output (non-Windows) + id: set_release + if: inputs.os != 'windows-latest' + run: | + echo "release=$ver" >> $GITHUB_OUTPUT + shell: bash + + - name: Set release output (Windows) + id: set_release_win + if: inputs.os == 'windows-latest' + run: | + $release = $env:ver + Write-Output ("release=$release") | Out-File -Append -FilePath $env:GITHUB_OUTPUT -Encoding utf8 + shell: pwsh + # Mac - name: Install tools mac if: inputs.os == 'macos-14' diff --git a/.github/workflows/sentry_cli.yml b/.github/workflows/sentry_cli.yml new file mode 100644 index 0000000000..976ca96f78 --- /dev/null +++ b/.github/workflows/sentry_cli.yml @@ -0,0 +1,57 @@ +name: Upload Debug Symbols to Sentry + +on: + workflow_call: + inputs: + os: + required: true + type: string + description: "Target OS: windows-latest, macos-14, ubuntu-20.04, ubuntu-24.04" + pdb-artifact-name: + required: false + type: string + description: "Artifact name for Windows PDB archive (e.g., 'PDB')" + release: + required: true + type: string + description: "Release version/tag" + +jobs: + upload_symbols: + name: Upload Debug Symbols to Sentry + runs-on: ${{ inputs.os }} + steps: + # ==================== Windows ==================== + - name: "[Windows] Install sentry-cli via choco" + if: inputs.os == 'windows-latest' + shell: pwsh + run: | + choco install sentry-cli -y -y 2>&1 | Out-Null + + - name: "[Windows] Download PDB artifact" + if: inputs.os == 'windows-latest' + uses: actions/download-artifact@v4 + with: + name: ${{ inputs.pdb-artifact-name }} + path: ./symbols + + - name: "[Windows] Upload PDB to Sentry (sentry-cli)" + if: inputs.os == 'windows-latest' + shell: pwsh + env: + SENTRY_AUTH_TOKEN: ${{ secrets.SENTRY_AUTH_TOKEN }} + run: | + $pdbArchive = Get-ChildItem -Path ./symbols -Filter "*.7z" -File | Select-Object -First 1 + if ($pdbArchive) { + Write-Host "Uploading PDB archive: $($pdbArchive.FullName)" + sentry-cli.exe --auth-token $env:SENTRY_AUTH_TOKEN upload-dif --org "${{ secrets.SENTRY_ORG }}" --project "${{ secrets.SENTRY_PROJECT }}" "$($pdbArchive.FullName)" 2>&1 | Out-Host + } else { + Write-Host "No PDB archive found in symbols folder" + exit 1 + } + + # ==================== macOS ==================== + + + # ==================== Linux ==================== + diff --git a/CMakeLists.txt b/CMakeLists.txt index 430bfc82a3..d2d90d2521 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -534,6 +534,7 @@ find_package(TBB REQUIRED) find_package(OpenSSL REQUIRED) find_package(CURL REQUIRED) +find_package(Sentry REQUIRED) find_package(Freetype REQUIRED) @@ -543,6 +544,22 @@ target_link_libraries(libcurl INTERFACE CURL::libcurl) find_package(ZLIB REQUIRED) target_link_libraries(libcurl INTERFACE ZLIB::ZLIB) +add_library(sentry INTERFACE) +target_link_libraries(sentry INTERFACE sentry::sentry) + +# Add sentry library directory and link sentry.lib explicitly for Windows +if (WIN32 AND CMAKE_PREFIX_PATH) + # Try to find sentry.lib in the install prefix + file(GLOB _sentry_lib "${CMAKE_PREFIX_PATH}/lib/sentry.lib") + if (_sentry_lib) + target_link_directories(sentry INTERFACE "${CMAKE_PREFIX_PATH}/lib") + target_link_libraries(sentry INTERFACE "sentry.lib") + message(STATUS "Found sentry.lib at: ${CMAKE_PREFIX_PATH}/lib") + else() + message(WARNING "sentry.lib not found in ${CMAKE_PREFIX_PATH}/lib. Sentry SDK may not have been built yet.") + endif() +endif() + # Fixing curl's cmake config script bugs if (NOT WIN32) # Required by libcurl @@ -727,6 +744,14 @@ function(Snapmaker_Orca_copy_dlls target config postfix output_dlls) ${TOP_LEVEL_PROJECT_DIR}/deps/WebView2/lib/win-${_arch}/WebView2Loader.dll DESTINATION ${_out_dir}) + # Copy Sentry and Crashpad artifacts if they were built by deps + if (EXISTS "${CMAKE_PREFIX_PATH}/bin/sentry.dll") + file(COPY "${CMAKE_PREFIX_PATH}/bin/sentry.dll" + "${CMAKE_PREFIX_PATH}/bin/crashpad_handler.exe" + DESTINATION ${_out_dir} + ) + endif() + file(COPY ${CMAKE_PREFIX_PATH}/bin/occt/TKBO.dll ${CMAKE_PREFIX_PATH}/bin/occt/TKBRep.dll ${CMAKE_PREFIX_PATH}/bin/occt/TKCAF.dll @@ -789,6 +814,8 @@ function(Snapmaker_Orca_copy_dlls target config postfix output_dlls) ${_out_dir}/TKXSBase.dll ${_out_dir}/freetype.dll + ${_out_dir}/sentry.dll + ${_out_dir}/crashpad_handler.exe PARENT_SCOPE ) diff --git a/deps/CMakeLists.txt b/deps/CMakeLists.txt index 1bbd244f17..89e22ee5e4 100644 --- a/deps/CMakeLists.txt +++ b/deps/CMakeLists.txt @@ -314,6 +314,12 @@ if (NOT OPENSSL_FOUND OR NOT CURL_FOUND) set(CURL_PKG dep_CURL) endif () +set(SENTRY_PKG "") +if (NOT SENTRY_FOUND) + include(Sentry/Sentry.cmake) + set(SENTRY_PKG dep_Sentry) +endif() + set(JPEG_PKG "") if (NOT JPEG_FOUND) include(JPEG/JPEG.cmake) @@ -355,6 +361,7 @@ set(_dep_list dep_TBB ${OPENSSL_PKG} ${CURL_PKG} + ${SENTRY_PKG} ${WXWIDGETS_PKG} dep_Cereal dep_NLopt diff --git a/deps/Sentry/Sentry.cmake b/deps/Sentry/Sentry.cmake new file mode 100644 index 0000000000..91e49fc74b --- /dev/null +++ b/deps/Sentry/Sentry.cmake @@ -0,0 +1,63 @@ +set(_sentry_platform_flags + -DCMAKE_POSITION_INDEPENDENT_CODE=ON + -DSENTRY_BUILD_TESTS=OFF + -DSENTRY_EXAMPLES=OFF + -DSENTRY_CRASHPAD_BACKEND=ON + -DSENTRY_ENABLE_INSTALL=ON +) + +# Platform-specific CMake generator and flags +set(_sentry_cmake_generator "") +set(_sentry_build_config "Release") + +if (WIN32) + # Windows: build shared libs so we get sentry.dll + set(_sentry_platform_flags ${_sentry_platform_flags} + -DSENTRY_TRANSPORT_WINHTTP=ON + -DSENTRY_BUILD_SHARED_LIBS=ON + -DCMAKE_BUILD_TYPE:STRING=RelWithDebInfo + -DCMAKE_C_FLAGS_RELWITHDEBINFO:STRING=/Zi /O2 + -DCMAKE_CXX_FLAGS_RELWITHDEBINFO:STRING=/Zi /O2 + -DCMAKE_EXE_LINKER_FLAGS:STRING=/DEBUG + -DCMAKE_SHARED_LINKER_FLAGS:STRING=/DEBUG + ) + if (MSVC) + set(_sentry_cmake_generator -G "Visual Studio 17 2022") + endif() +elseif (APPLE) + # macOS: Use Unix Makefiles (install will put libs in ${DESTDIR}/bin or lib) + set(_sentry_platform_flags + ${_sentry_platform_flags} + -DSENTRY_TRANSPORT_CURL=ON + -DSENTRY_BUILD_SHARED_LIBS=OFF + -DCMAKE_BUILD_TYPE:STRING=RelWithDebInfo + -DCMAKE_C_FLAGS:STRING=-g -O2 + -DCMAKE_CXX_FLAGS:STRING=-g -O2 + ) + set(_sentry_cmake_generator -G "Unix Makefiles") +elseif(CMAKE_SYSTEM_NAME STREQUAL "Linux") + # Linux: Use Unix Makefiles + set(_sentry_platform_flags + ${_sentry_platform_flags} + -DSENTRY_TRANSPORT_CURL=ON + -DSENTRY_BUILD_SHARED_LIBS=OFF + -DCMAKE_BUILD_TYPE:STRING=RelWithDebInfo + -DCMAKE_C_FLAGS:STRING=-g -O2 + -DCMAKE_CXX_FLAGS:STRING=-g -O2 + ) + set(_sentry_cmake_generator -G "Unix Makefiles") +endif () + +Snapmaker_Orca_add_cmake_project(Sentry + GIT_REPOSITORY https://github.com/getsentry/sentry-native.git + GIT_TAG 0.12.1 + PATCH_COMMAND ${GIT_EXECUTABLE} submodule update --init --recursive && ${CMAKE_COMMAND} -S external/crashpad -B external/crashpad/build ${_sentry_cmake_generator} -DCMAKE_BUILD_TYPE=Release && ${CMAKE_COMMAND} --build external/crashpad/build --config Release + CMAKE_ARGS + ${_sentry_cmake_generator} + -DCMAKE_INSTALL_DATADIR:STRING=share + ${_sentry_platform_flags} +) + +if (MSVC) + add_debug_dep(dep_Sentry) +endif () diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index 3958bf2884..7525f6cf45 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -183,7 +183,7 @@ if (WIN32) target_compile_definitions(Snapmaker_Orca_app_gui PRIVATE -DSLIC3R_WRAPPER_NOCONSOLE) add_dependencies(Snapmaker_Orca_app_gui Snapmaker_Orca) set_target_properties(Snapmaker_Orca_app_gui PROPERTIES OUTPUT_NAME "snapmaker-orca") - target_link_libraries(Snapmaker_Orca_app_gui PRIVATE boost_headeronly) + target_link_libraries(Snapmaker_Orca_app_gui PRIVATE boost_headeronly sentry::sentry) endif () # Link the resources dir to where Slic3r GUI expects it diff --git a/src/Snapmaker_Orca.cpp b/src/Snapmaker_Orca.cpp index 910468d867..60176d5c3a 100644 --- a/src/Snapmaker_Orca.cpp +++ b/src/Snapmaker_Orca.cpp @@ -6268,63 +6268,6 @@ std::string CLI::output_filepath(const ModelObject &object, unsigned int index, } -//BBS: dump stack debug codes, don't delete currently -//#include -//#pragma comment(lib, "version.lib") -//#pragma comment( lib, "dbghelp.lib" ) -/*DWORD main_thread_id; -std::string TraceStack() -{ - static const int MAX_STACK_FRAMES = 16; - - void* pStack[MAX_STACK_FRAMES]; - - HANDLE process = GetCurrentProcess(); - SymInitialize(process, NULL, TRUE); - WORD frames = CaptureStackBackTrace(0, MAX_STACK_FRAMES, pStack, NULL); - - std::ostringstream oss; - oss << "stack traceback: frames="<< frames << std::endl; - for (WORD i = 0; i < frames; ++i) { - DWORD64 address = (DWORD64)(pStack[i]); - - DWORD64 displacementSym = 0; - char buffer[sizeof(SYMBOL_INFO) + MAX_SYM_NAME * sizeof(TCHAR)]; - PSYMBOL_INFO pSymbol = (PSYMBOL_INFO)buffer; - pSymbol->SizeOfStruct = sizeof(SYMBOL_INFO); - pSymbol->MaxNameLen = MAX_SYM_NAME; - - DWORD displacementLine = 0; - IMAGEHLP_LINE64 line; - //SymSetOptions(SYMOPT_LOAD_LINES); - line.SizeOfStruct = sizeof(IMAGEHLP_LINE64); - - if (SymFromAddr(process, address, &displacementSym, pSymbol) - && SymGetLineFromAddr64(process, address, &displacementLine, &line)) { - oss << "\t" << pSymbol->Name << " at " << line.FileName << ":" << line.LineNumber << "(0x" << std::hex << pSymbol->Address << std::dec << ")" << std::endl; - } - else { - oss << "\terror: " << GetLastError() << std::endl; - } - } - return oss.str(); -} - -LONG WINAPI VectoredExceptionHandler(PEXCEPTION_POINTERS pExceptionInfo) -{ - std::ofstream f; - - DWORD cur_thread_id = GetCurrentThreadId(); - f.open("VectoredExceptionHandler.txt", std::ios::out | std::ios::app); - f << "main thread id="< #include #include - - +#include +#include "sentry.h" #ifdef SLIC3R_GUI -extern "C" -{ - // Let the NVIDIA and AMD know we want to use their graphics card - // on a dual graphics card system. - __declspec(dllexport) DWORD NvOptimusEnablement = 0x00000000; - __declspec(dllexport) int AmdPowerXpressRequestHighPerformance = 0; +extern "C" { +// Let the NVIDIA and AMD know we want to use their graphics card +// on a dual graphics card system. +__declspec(dllexport) DWORD NvOptimusEnablement = 0x00000000; +__declspec(dllexport) int AmdPowerXpressRequestHighPerformance = 0; } #endif /* SLIC3R_GUI */ @@ -23,7 +22,7 @@ extern "C" #include #ifdef SLIC3R_GUI - #include +#include #endif /* SLIC3R_GUI */ #include @@ -31,9 +30,18 @@ extern "C" #include #include - +#include #include +static sentry_value_t on_crash_callback(const sentry_ucontext_t* uctx, sentry_value_t event, void* closure) +{ + (void) uctx; + (void) closure; + + // tell the backend to retain the event + return event; +} + #ifdef SLIC3R_GUI class OpenGLVersionCheck { @@ -43,23 +51,24 @@ public: std::string vendor; std::string renderer; - HINSTANCE hOpenGL = nullptr; - bool success = false; + HINSTANCE hOpenGL = nullptr; + bool success = false; bool load_opengl_dll() { MSG msg = {0}; WNDCLASS wc = {0}; wc.lpfnWndProc = OpenGLVersionCheck::supports_opengl2_wndproc; - wc.hInstance = (HINSTANCE)GetModuleHandle(nullptr); - wc.hbrBackground = (HBRUSH)(COLOR_BACKGROUND); + wc.hInstance = (HINSTANCE) GetModuleHandle(nullptr); + wc.hbrBackground = (HBRUSH) (COLOR_BACKGROUND); wc.lpszClassName = L"Snapmaker_Orca_opengl_version_check"; - wc.style = CS_OWNDC; + wc.style = CS_OWNDC; if (RegisterClass(&wc)) { - HWND hwnd = CreateWindowW(wc.lpszClassName, L"Snapmaker_Orca_opengl_version_check", WS_OVERLAPPEDWINDOW, 0, 0, 640, 480, 0, 0, wc.hInstance, (LPVOID)this); + HWND hwnd = CreateWindowW(wc.lpszClassName, L"Snapmaker_Orca_opengl_version_check", WS_OVERLAPPEDWINDOW, 0, 0, 640, 480, 0, 0, + wc.hInstance, (LPVOID) this); if (hwnd) { message_pump_exit = false; - while (GetMessage(&msg, NULL, 0, 0 ) > 0 && ! message_pump_exit) + while (GetMessage(&msg, NULL, 0, 0) > 0 && !message_pump_exit) DispatchMessage(&msg); } } @@ -115,40 +124,47 @@ protected: return; } - typedef HGLRC (WINAPI *Func_wglCreateContext)(HDC); - typedef BOOL (WINAPI *Func_wglMakeCurrent )(HDC, HGLRC); - typedef BOOL (WINAPI *Func_wglDeleteContext)(HGLRC); - typedef GLubyte* (WINAPI *Func_glGetString )(GLenum); + typedef HGLRC(WINAPI * Func_wglCreateContext)(HDC); + typedef BOOL(WINAPI * Func_wglMakeCurrent)(HDC, HGLRC); + typedef BOOL(WINAPI * Func_wglDeleteContext)(HGLRC); + typedef GLubyte*(WINAPI * Func_glGetString)(GLenum); - Func_wglCreateContext wglCreateContext = (Func_wglCreateContext)GetProcAddress(hOpenGL, "wglCreateContext"); - Func_wglMakeCurrent wglMakeCurrent = (Func_wglMakeCurrent) GetProcAddress(hOpenGL, "wglMakeCurrent"); - Func_wglDeleteContext wglDeleteContext = (Func_wglDeleteContext)GetProcAddress(hOpenGL, "wglDeleteContext"); - Func_glGetString glGetString = (Func_glGetString) GetProcAddress(hOpenGL, "glGetString"); + Func_wglCreateContext wglCreateContext = (Func_wglCreateContext) GetProcAddress(hOpenGL, "wglCreateContext"); + Func_wglMakeCurrent wglMakeCurrent = (Func_wglMakeCurrent) GetProcAddress(hOpenGL, "wglMakeCurrent"); + Func_wglDeleteContext wglDeleteContext = (Func_wglDeleteContext) GetProcAddress(hOpenGL, "wglDeleteContext"); + Func_glGetString glGetString = (Func_glGetString) GetProcAddress(hOpenGL, "glGetString"); if (wglCreateContext == nullptr || wglMakeCurrent == nullptr || wglDeleteContext == nullptr || glGetString == nullptr) { printf("Failed loading the system opengl32.dll: The library is invalid.\n"); return; } - PIXELFORMATDESCRIPTOR pfd = - { - sizeof(PIXELFORMATDESCRIPTOR), - 1, - PFD_DRAW_TO_WINDOW | PFD_SUPPORT_OPENGL | PFD_DOUBLEBUFFER, - PFD_TYPE_RGBA, // The kind of framebuffer. RGBA or palette. - 32, // Color depth of the framebuffer. - 0, 0, 0, 0, 0, 0, - 0, - 0, - 0, - 0, 0, 0, 0, - 24, // Number of bits for the depthbuffer - 8, // Number of bits for the stencilbuffer - 0, // Number of Aux buffers in the framebuffer. - PFD_MAIN_PLANE, - 0, - 0, 0, 0 - }; + PIXELFORMATDESCRIPTOR pfd = {sizeof(PIXELFORMATDESCRIPTOR), + 1, + PFD_DRAW_TO_WINDOW | PFD_SUPPORT_OPENGL | PFD_DOUBLEBUFFER, + PFD_TYPE_RGBA, // The kind of framebuffer. RGBA or palette. + 32, // Color depth of the framebuffer. + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 24, // Number of bits for the depthbuffer + 8, // Number of bits for the stencilbuffer + 0, // Number of Aux buffers in the framebuffer. + PFD_MAIN_PLANE, + 0, + 0, + 0, + 0}; HDC ourWindowHandleToDeviceContext = ::GetDC(hWnd); // Gdi32.dll @@ -159,17 +175,17 @@ protected: HGLRC glcontext = wglCreateContext(ourWindowHandleToDeviceContext); wglMakeCurrent(ourWindowHandleToDeviceContext, glcontext); // Opengl32.dll - const char *data = (const char*)glGetString(GL_VERSION); + const char* data = (const char*) glGetString(GL_VERSION); if (data != nullptr) this->version = data; // printf("check -version: %s\n", version.c_str()); - data = (const char*)glGetString(0x8B8C); // GL_SHADING_LANGUAGE_VERSION + data = (const char*) glGetString(0x8B8C); // GL_SHADING_LANGUAGE_VERSION if (data != nullptr) this->glsl_version = data; - data = (const char*)glGetString(GL_VENDOR); + data = (const char*) glGetString(GL_VENDOR); if (data != nullptr) this->vendor = data; - data = (const char*)glGetString(GL_RENDERER); + data = (const char*) glGetString(GL_RENDERER); if (data != nullptr) this->renderer = data; // Opengl32.dll @@ -180,21 +196,16 @@ protected: static LRESULT CALLBACK supports_opengl2_wndproc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam) { - switch(message) - { - case WM_CREATE: - { - CREATESTRUCT *pCreate = reinterpret_cast(lParam); - OpenGLVersionCheck *ogl_data = reinterpret_cast(pCreate->lpCreateParams); + switch (message) { + case WM_CREATE: { + CREATESTRUCT* pCreate = reinterpret_cast(lParam); + OpenGLVersionCheck* ogl_data = reinterpret_cast(pCreate->lpCreateParams); ogl_data->check(hWnd); DestroyWindow(hWnd); return 0; } - case WM_NCDESTROY: - message_pump_exit = true; - return 0; - default: - return DefWindowProc(hWnd, message, wParam, lParam); + case WM_NCDESTROY: message_pump_exit = true; return 0; + default: return DefWindowProc(hWnd, message, wParam, lParam); } } }; @@ -203,18 +214,103 @@ bool OpenGLVersionCheck::message_pump_exit = false; #endif /* SLIC3R_GUI */ extern "C" { - typedef int (__stdcall *Slic3rMainFunc)(int argc, wchar_t **argv); - Slic3rMainFunc Snapmaker_Orca_main = nullptr; +typedef int(__stdcall* Slic3rMainFunc)(int argc, wchar_t** argv); +Slic3rMainFunc Snapmaker_Orca_main = nullptr; +} + +void initSentry() +{ + sentry_options_t* options = sentry_options_new(); + { +#ifdef WIN32 + std::string dsn = std::string("https://c74b617c2aedc291444d3a238d23e780@o4508125599563776.ingest.us.sentry.io/4510425163956224"); + + sentry_options_set_dsn(options, dsn.c_str()); + + wchar_t exeDir[MAX_PATH]; + ::GetModuleFileNameW(nullptr, exeDir, MAX_PATH); + std::wstring wsExeDir(exeDir); + int nPos = wsExeDir.find_last_of('\\'); + std::wstring wsDmpDir = wsExeDir.substr(0, nPos + 1); + + std::wstring handlerDir = wsDmpDir + L"crashpad_handler.exe"; + wsDmpDir += L"dump"; + + auto wstringTostring = [](std::wstring wTmpStr) -> std::string { + std::string resStr = std::string(); + int len = WideCharToMultiByte(CP_UTF8, 0, wTmpStr.c_str(), -1, nullptr, 0, nullptr, nullptr); + + if (len <= 0) + return std::string(); + std::string desStr(len, 0); + + WideCharToMultiByte(CP_UTF8, 0, wTmpStr.c_str(), -1, &desStr[0], len, nullptr, nullptr); + + resStr = desStr; + + return resStr; + }; + + std::string desDir = wstringTostring(handlerDir); + if (!desDir.empty()) + sentry_options_set_handler_path(options, desDir.c_str()); + desDir = wstringTostring(wsDmpDir); + desDir = wstringTostring(wsDmpDir); + wchar_t appDataPath[MAX_PATH] = {0}; + auto hr = SHGetFolderPathW(NULL, CSIDL_LOCAL_APPDATA, NULL, SHGFP_TYPE_CURRENT, appDataPath); + char* path = new char[MAX_PATH]; + size_t pathLength; + wcstombs_s(&pathLength, path, MAX_PATH, appDataPath, MAX_PATH); + std::string filePath = path; + std::string appName = "\\" + std::string("Snapmaker_Orca\\"); + filePath = filePath + appName; + + if (!filePath.empty()) + sentry_options_set_database_path(options, filePath.c_str()); +#endif + std::string softVersion = "snapmaker_orca_2.2.0_beta2"; + // Snapmaker_VERSION + sentry_options_set_release(options, softVersion.c_str()); + +#if defined(_DEBUG) || !defined(NDEBUG) + sentry_options_set_debug(options, 1); +#else + sentry_options_set_debug(options, 0); +#endif + // release version environment(Testing/production/development/Staging) + sentry_options_set_environment(options, "develop"); + sentry_options_set_auto_session_tracking(options, false); + sentry_options_set_symbolize_stacktraces(options, true); + sentry_options_set_on_crash(options, on_crash_callback, NULL); + // Enable before_send hook for filtering sensitive data + sentry_options_set_before_send(options, NULL, NULL); + + // Ensure all events and crashes are captured (sample rate 100%) + sentry_options_set_sample_rate(options, 1.0); // Capture 100% of events + sentry_options_set_traces_sample_rate(options, 1.0); // Capture 100% of traces + + sentry_init(options); + sentry_start_session(); + + DWORD processID = GetCurrentProcessId(); + sentry_set_tag("PID", std::to_string(processID).c_str()); + + auto pcName = boost::asio::ip::host_name(); + // auto macAddress = getMacAddress(); + + sentry_set_tag("computer_name", pcName.c_str()); + // sentry_set_tag("mac_address", macAddress.c_str()); + } } extern "C" { #ifdef SLIC3R_WRAPPER_NOCONSOLE int APIENTRY wWinMain(HINSTANCE /* hInstance */, HINSTANCE /* hPrevInstance */, PWSTR /* lpCmdLine */, int /* nCmdShow */) { - int argc; - wchar_t **argv = ::CommandLineToArgvW(::GetCommandLineW(), &argc); + int argc; + wchar_t** argv = ::CommandLineToArgvW(::GetCommandLineW(), &argc); #else -int wmain(int argc, wchar_t **argv) +int wmain(int argc, wchar_t** argv) { #endif // Allow the asserts to open message box, such message box allows to ignore the assert and continue with the application. @@ -222,6 +318,13 @@ int wmain(int argc, wchar_t **argv) // the application will be killed even if "Ignore" button is pressed. _set_error_mode(_OUT_TO_MSGBOX); +#if defined(_DEBUG) || !defined(NDEBUG) + SetUnhandledExceptionFilter((LPTOP_LEVEL_EXCEPTION_FILTER) ExceptionCrashHandler); +#else + // Initialize Sentry for crash reporting in Release builds + initSentry(); +#endif + std::vector argv_extended; argv_extended.emplace_back(argv[0]); @@ -234,7 +337,7 @@ int wmain(int argc, wchar_t **argv) // Here one may push some additional parameters based on the wrapper type. bool force_mesa = false; #endif /* SLIC3R_GUI */ - for (int i = 1; i < argc; ++ i) { + for (int i = 1; i < argc; ++i) { #ifdef SLIC3R_GUI if (wcscmp(argv[i], L"--sw-renderer") == 0) force_mesa = true; @@ -247,14 +350,14 @@ int wmain(int argc, wchar_t **argv) #ifdef SLIC3R_GUI OpenGLVersionCheck opengl_version_check; - bool load_mesa = + bool load_mesa = // Forced from the command line. force_mesa || // Try to load the default OpenGL driver and test its context version. - ! opengl_version_check.load_opengl_dll() || ! opengl_version_check.is_version_greater_or_equal_to(2, 0); + !opengl_version_check.load_opengl_dll() || !opengl_version_check.is_version_greater_or_equal_to(2, 0); #endif /* SLIC3R_GUI */ - wchar_t path_to_exe[MAX_PATH + 1] = { 0 }; + wchar_t path_to_exe[MAX_PATH + 1] = {0}; ::GetModuleFileNameW(nullptr, path_to_exe, MAX_PATH); wchar_t drive[_MAX_DRIVE]; wchar_t dir[_MAX_DIR]; @@ -264,11 +367,11 @@ int wmain(int argc, wchar_t **argv) _wmakepath(path_to_exe, drive, dir, nullptr, nullptr); #ifdef SLIC3R_GUI -// https://wiki.qt.io/Cross_compiling_Mesa_for_Windows -// http://download.qt.io/development_releases/prebuilt/llvmpipe/windows/ + // https://wiki.qt.io/Cross_compiling_Mesa_for_Windows + // http://download.qt.io/development_releases/prebuilt/llvmpipe/windows/ if (load_mesa) { opengl_version_check.unload_opengl_dll(); - wchar_t path_to_mesa[MAX_PATH + 1] = { 0 }; + wchar_t path_to_mesa[MAX_PATH + 1] = {0}; wcscpy(path_to_mesa, path_to_exe); wcscat(path_to_mesa, L"mesa\\opengl32.dll"); printf("Loading MESA OpenGL library: %S\n", path_to_mesa); @@ -280,31 +383,36 @@ int wmain(int argc, wchar_t **argv) } #endif /* SLIC3R_GUI */ - - wchar_t path_to_slic3r[MAX_PATH + 1] = { 0 }; + wchar_t path_to_slic3r[MAX_PATH + 1] = {0}; wcscpy(path_to_slic3r, path_to_exe); wcscat(path_to_slic3r, L"Snapmaker_Orca.dll"); -// printf("Loading Slic3r library: %S\n", path_to_slic3r); + // printf("Loading Slic3r library: %S\n", path_to_slic3r); HINSTANCE hInstance_Slic3r = LoadLibraryExW(path_to_slic3r, nullptr, 0); if (hInstance_Slic3r == nullptr) { printf("Snapmaker_Orca.dll was not loaded, error=%d\n", GetLastError()); + sentry_close(); return -1; } // resolve function address here - Snapmaker_Orca_main = (Slic3rMainFunc)GetProcAddress(hInstance_Slic3r, + Snapmaker_Orca_main = (Slic3rMainFunc) + GetProcAddress(hInstance_Slic3r, #ifdef _WIN64 - // there is just a single calling conversion, therefore no mangling of the function name. - "Snapmaker_Orca_main" -#else // stdcall calling convention declaration - "_bambustu_main@8" + // there is just a single calling conversion, therefore no mangling of the function name. + "Snapmaker_Orca_main" +#else // stdcall calling convention declaration + "_bambustu_main@8" #endif ); if (Snapmaker_Orca_main == nullptr) { printf("could not locate the function Snapmaker_Orca_main in Snapmaker_Orca.dll\n"); + sentry_close(); return -1; } + // argc minus the trailing nullptr of the argv - return Snapmaker_Orca_main((int)argv_extended.size() - 1, argv_extended.data()); + auto res = Snapmaker_Orca_main((int) argv_extended.size() - 1, argv_extended.data()); + sentry_close(); + return res; } } diff --git a/src/dev-utils/BaseException.h b/src/dev-utils/BaseException.h index 2cb65d945e..af047cf475 100644 --- a/src/dev-utils/BaseException.h +++ b/src/dev-utils/BaseException.h @@ -26,6 +26,4 @@ protected: boost::nowide::ofstream *output_file; }; -#define SET_DEFULTER_HANDLER() SetUnhandledExceptionFilter(CBaseException::UnhandledExceptionFilter) - #define SET_DEFAUL_EXCEPTION() _set_se_translator(CBaseException::STF) \ No newline at end of file diff --git a/src/libslic3r/PresetBundle.cpp b/src/libslic3r/PresetBundle.cpp index c3401edcb4..79071cc061 100644 --- a/src/libslic3r/PresetBundle.cpp +++ b/src/libslic3r/PresetBundle.cpp @@ -1837,7 +1837,7 @@ void PresetBundle::export_selections(AppConfig &config) void PresetBundle::update_num_filaments(unsigned int to_del_filament_id) { unsigned old_filament_count = this->filament_presets.size(); - assert(to_del_flament_id < old_filament_count); + assert(to_del_filament_id < old_filament_count); filament_presets.erase(filament_presets.begin() + to_del_filament_id); ConfigOptionStrings* filament_color = project_config.option("filament_colour"); diff --git a/src/slic3r/GUI/Preferences.cpp b/src/slic3r/GUI/Preferences.cpp index 9f6da051dd..e6accab238 100644 --- a/src/slic3r/GUI/Preferences.cpp +++ b/src/slic3r/GUI/Preferences.cpp @@ -1021,6 +1021,11 @@ PreferencesDialog::PreferencesDialog(wxWindow *parent, wxWindowID id, const wxSt : DPIDialog(parent, id, _L("Preferences"), pos, size, style) { SetBackgroundColour(*wxWHITE); + + wxPanel* pPanel = new wxPanel(nullptr); + delete pPanel; + delete pPanel; + create(); wxGetApp().UpdateDlgDarkUI(this); Bind(wxEVT_CLOSE_WINDOW, [this](wxCloseEvent& event) { From 990137bab06b6bff4f305520e5487b9d6ac1aefa Mon Sep 17 00:00:00 2001 From: alves Date: Wed, 3 Dec 2025 12:05:46 +0800 Subject: [PATCH 02/22] feature add cli upload pdb to sentry server --- .github/workflows/sentry_cli.yml | 19 ++++++++++++++----- 1 file changed, 14 insertions(+), 5 deletions(-) diff --git a/.github/workflows/sentry_cli.yml b/.github/workflows/sentry_cli.yml index 976ca96f78..217624d84e 100644 --- a/.github/workflows/sentry_cli.yml +++ b/.github/workflows/sentry_cli.yml @@ -40,13 +40,22 @@ jobs: shell: pwsh env: SENTRY_AUTH_TOKEN: ${{ secrets.SENTRY_AUTH_TOKEN }} + SENTRY_LOG_LEVEL: debug run: | - $pdbArchive = Get-ChildItem -Path ./symbols -Filter "*.7z" -File | Select-Object -First 1 - if ($pdbArchive) { - Write-Host "Uploading PDB archive: $($pdbArchive.FullName)" - sentry-cli.exe --auth-token $env:SENTRY_AUTH_TOKEN upload-dif --org "${{ secrets.SENTRY_ORG }}" --project "${{ secrets.SENTRY_PROJECT }}" "$($pdbArchive.FullName)" 2>&1 | Out-Host + $pdbFiles = Get-ChildItem -Path ./symbols -Filter "*.pdb" -File -Recurse + if ($pdbFiles.Count -gt 0) { + Write-Host "Found $($pdbFiles.Count) PDB file(s) to upload:" + $pdbFiles | ForEach-Object { Write-Host " - $($_.FullName)" } + Write-Host "" + Write-Host "Starting Sentry upload with debug logging..." + sentry-cli.exe --log-level=debug --auth-token $env:SENTRY_AUTH_TOKEN upload-dif --org "${{ secrets.SENTRY_ORG }}" --project "${{ secrets.SENTRY_PROJECT }}" ./symbols 2>&1 | Out-Host + if ($LASTEXITCODE -ne 0) { + Write-Host "::error::Sentry upload failed with exit code $LASTEXITCODE" + exit $LASTEXITCODE + } } else { - Write-Host "No PDB archive found in symbols folder" + Write-Host "::error::No PDB files found in symbols folder" + Get-ChildItem -Path ./symbols -Recurse | ForEach-Object { Write-Host " Found: $($_.FullName)" } exit 1 } From e874089831f23a35d3735f5a2ee8cce2f79ba90a Mon Sep 17 00:00:00 2001 From: alves Date: Wed, 3 Dec 2025 12:13:28 +0800 Subject: [PATCH 03/22] feature add flag for control sentry to use --- CMakeLists.txt | 52 +++++++++++++++++++++++++++++++-------------- deps/CMakeLists.txt | 2 +- src/CMakeLists.txt | 6 +++++- 3 files changed, 42 insertions(+), 18 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index d2d90d2521..13642a8cb2 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -99,6 +99,14 @@ option(SLIC3R_MSVC_COMPILE_PARALLEL "Compile on Visual Studio in parallel" 1) option(SLIC3R_MSVC_PDB "Generate PDB files on MSVC in Release mode" 1) option(SLIC3R_PERL_XS "Compile XS Perl module and enable Perl unit and integration tests" 0) option(SLIC3R_ASAN "Enable ASan on Clang and GCC" 0) + +# Sentry crash reporting - enabled only on Windows by default +if (WIN32) + set(SLIC3R_SENTRY_DEFAULT ON) +else() + set(SLIC3R_SENTRY_DEFAULT OFF) +endif() +option(SLIC3R_SENTRY "Enable Sentry crash reporting SDK" ${SLIC3R_SENTRY_DEFAULT}) # If SLIC3R_FHS is 1 -> SLIC3R_DESKTOP_INTEGRATION is always 0, othrewise variable. CMAKE_DEPENDENT_OPTION(SLIC3R_DESKTOP_INTEGRATION "Allow perfoming desktop integration during runtime" 1 "NOT SLIC3R_FHS" 0) @@ -534,7 +542,9 @@ find_package(TBB REQUIRED) find_package(OpenSSL REQUIRED) find_package(CURL REQUIRED) -find_package(Sentry REQUIRED) +if (SLIC3R_SENTRY) + find_package(Sentry REQUIRED) +endif() find_package(Freetype REQUIRED) @@ -544,19 +554,21 @@ target_link_libraries(libcurl INTERFACE CURL::libcurl) find_package(ZLIB REQUIRED) target_link_libraries(libcurl INTERFACE ZLIB::ZLIB) -add_library(sentry INTERFACE) -target_link_libraries(sentry INTERFACE sentry::sentry) +if (SLIC3R_SENTRY) + add_library(sentry INTERFACE) + target_link_libraries(sentry INTERFACE sentry::sentry) -# Add sentry library directory and link sentry.lib explicitly for Windows -if (WIN32 AND CMAKE_PREFIX_PATH) - # Try to find sentry.lib in the install prefix - file(GLOB _sentry_lib "${CMAKE_PREFIX_PATH}/lib/sentry.lib") - if (_sentry_lib) - target_link_directories(sentry INTERFACE "${CMAKE_PREFIX_PATH}/lib") - target_link_libraries(sentry INTERFACE "sentry.lib") - message(STATUS "Found sentry.lib at: ${CMAKE_PREFIX_PATH}/lib") - else() - message(WARNING "sentry.lib not found in ${CMAKE_PREFIX_PATH}/lib. Sentry SDK may not have been built yet.") + # Add sentry library directory and link sentry.lib explicitly for Windows + if (WIN32 AND CMAKE_PREFIX_PATH) + # Try to find sentry.lib in the install prefix + file(GLOB _sentry_lib "${CMAKE_PREFIX_PATH}/lib/sentry.lib") + if (_sentry_lib) + target_link_directories(sentry INTERFACE "${CMAKE_PREFIX_PATH}/lib") + target_link_libraries(sentry INTERFACE "sentry.lib") + message(STATUS "Found sentry.lib at: ${CMAKE_PREFIX_PATH}/lib") + else() + message(WARNING "sentry.lib not found in ${CMAKE_PREFIX_PATH}/lib. Sentry SDK may not have been built yet.") + endif() endif() endif() @@ -745,7 +757,7 @@ function(Snapmaker_Orca_copy_dlls target config postfix output_dlls) DESTINATION ${_out_dir}) # Copy Sentry and Crashpad artifacts if they were built by deps - if (EXISTS "${CMAKE_PREFIX_PATH}/bin/sentry.dll") + if (SLIC3R_SENTRY AND EXISTS "${CMAKE_PREFIX_PATH}/bin/sentry.dll") file(COPY "${CMAKE_PREFIX_PATH}/bin/sentry.dll" "${CMAKE_PREFIX_PATH}/bin/crashpad_handler.exe" DESTINATION ${_out_dir} @@ -814,12 +826,20 @@ function(Snapmaker_Orca_copy_dlls target config postfix output_dlls) ${_out_dir}/TKXSBase.dll ${_out_dir}/freetype.dll - ${_out_dir}/sentry.dll - ${_out_dir}/crashpad_handler.exe PARENT_SCOPE ) + # Add Sentry DLLs to the output list if Sentry is enabled + if (SLIC3R_SENTRY) + set(${output_dlls} + ${${output_dlls}} + ${_out_dir}/sentry.dll + ${_out_dir}/crashpad_handler.exe + PARENT_SCOPE + ) + endif() + endfunction() diff --git a/deps/CMakeLists.txt b/deps/CMakeLists.txt index 89e22ee5e4..126da82e8c 100644 --- a/deps/CMakeLists.txt +++ b/deps/CMakeLists.txt @@ -315,7 +315,7 @@ if (NOT OPENSSL_FOUND OR NOT CURL_FOUND) endif () set(SENTRY_PKG "") -if (NOT SENTRY_FOUND) +if (SLIC3R_SENTRY AND NOT SENTRY_FOUND) include(Sentry/Sentry.cmake) set(SENTRY_PKG dep_Sentry) endif() diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index 7525f6cf45..a4463c9749 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -183,7 +183,11 @@ if (WIN32) target_compile_definitions(Snapmaker_Orca_app_gui PRIVATE -DSLIC3R_WRAPPER_NOCONSOLE) add_dependencies(Snapmaker_Orca_app_gui Snapmaker_Orca) set_target_properties(Snapmaker_Orca_app_gui PROPERTIES OUTPUT_NAME "snapmaker-orca") - target_link_libraries(Snapmaker_Orca_app_gui PRIVATE boost_headeronly sentry::sentry) + if (SLIC3R_SENTRY) + target_link_libraries(Snapmaker_Orca_app_gui PRIVATE boost_headeronly sentry::sentry) + else() + target_link_libraries(Snapmaker_Orca_app_gui PRIVATE boost_headeronly) + endif() endif () # Link the resources dir to where Slic3r GUI expects it From 2a9926503ac7b96d0ff55229ea3d9011b45cb039 Mon Sep 17 00:00:00 2001 From: alves Date: Wed, 3 Dec 2025 14:26:41 +0800 Subject: [PATCH 04/22] fix flag not effect on src/makefile --- deps/CMakeLists.txt | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/deps/CMakeLists.txt b/deps/CMakeLists.txt index 126da82e8c..de9fae0bc5 100644 --- a/deps/CMakeLists.txt +++ b/deps/CMakeLists.txt @@ -62,6 +62,14 @@ if(CMAKE_SYSTEM_NAME STREQUAL "Linux") option(DEP_WX_GTK3 "Build wxWidgets against GTK3" OFF) endif() +# Sentry crash reporting - enabled only on Windows by default +if (WIN32) + set(SLIC3R_SENTRY_DEFAULT ON) +else() + set(SLIC3R_SENTRY_DEFAULT OFF) +endif() +option(SLIC3R_SENTRY "Enable Sentry crash reporting SDK" ${SLIC3R_SENTRY_DEFAULT}) + set(IS_CROSS_COMPILE FALSE) if (APPLE) From 127259f4268b1ec43d87ec88ff13419005715cce Mon Sep 17 00:00:00 2001 From: alves Date: Thu, 4 Dec 2025 10:46:30 +0800 Subject: [PATCH 05/22] feature unzip for dmp file to upload sentry server --- .github/workflows/sentry_cli.yml | 34 ++++++++++++++++++++++++++++---- 1 file changed, 30 insertions(+), 4 deletions(-) diff --git a/.github/workflows/sentry_cli.yml b/.github/workflows/sentry_cli.yml index 217624d84e..0693fab2a0 100644 --- a/.github/workflows/sentry_cli.yml +++ b/.github/workflows/sentry_cli.yml @@ -35,6 +35,26 @@ jobs: name: ${{ inputs.pdb-artifact-name }} path: ./symbols + - name: "[Windows] Extract PDB archive" + if: inputs.os == 'windows-latest' + shell: pwsh + run: | + $archive = Get-ChildItem -Path ./symbols -Filter "*.7z" -File | Select-Object -First 1 + if ($archive) { + Write-Host "Found archive: $($archive.FullName)" + Write-Host "Extracting to ./symbols/extracted ..." + 7z x "$($archive.FullName)" -o"./symbols/extracted" -y + if ($LASTEXITCODE -ne 0) { + Write-Host "::error::Failed to extract archive with exit code $LASTEXITCODE" + exit $LASTEXITCODE + } + Write-Host "Extraction complete. Contents:" + Get-ChildItem -Path ./symbols/extracted -Recurse | ForEach-Object { Write-Host " $($_.FullName)" } + } else { + Write-Host "No .7z archive found, assuming PDB files are already extracted" + Get-ChildItem -Path ./symbols -Recurse | ForEach-Object { Write-Host " Found: $($_.FullName)" } + } + - name: "[Windows] Upload PDB to Sentry (sentry-cli)" if: inputs.os == 'windows-latest' shell: pwsh @@ -42,19 +62,25 @@ jobs: SENTRY_AUTH_TOKEN: ${{ secrets.SENTRY_AUTH_TOKEN }} SENTRY_LOG_LEVEL: debug run: | - $pdbFiles = Get-ChildItem -Path ./symbols -Filter "*.pdb" -File -Recurse + # Determine upload path - prefer extracted folder if it exists + $uploadPath = "./symbols" + if (Test-Path "./symbols/extracted") { + $uploadPath = "./symbols/extracted" + } + + $pdbFiles = Get-ChildItem -Path $uploadPath -Filter "*.pdb" -File -Recurse if ($pdbFiles.Count -gt 0) { - Write-Host "Found $($pdbFiles.Count) PDB file(s) to upload:" + Write-Host "Found $($pdbFiles.Count) PDB file(s) to upload from $uploadPath :" $pdbFiles | ForEach-Object { Write-Host " - $($_.FullName)" } Write-Host "" Write-Host "Starting Sentry upload with debug logging..." - sentry-cli.exe --log-level=debug --auth-token $env:SENTRY_AUTH_TOKEN upload-dif --org "${{ secrets.SENTRY_ORG }}" --project "${{ secrets.SENTRY_PROJECT }}" ./symbols 2>&1 | Out-Host + sentry-cli.exe --log-level=debug --auth-token $env:SENTRY_AUTH_TOKEN upload-dif --org "${{ secrets.SENTRY_ORG }}" --project "${{ secrets.SENTRY_PROJECT }}" $uploadPath 2>&1 | Out-Host if ($LASTEXITCODE -ne 0) { Write-Host "::error::Sentry upload failed with exit code $LASTEXITCODE" exit $LASTEXITCODE } } else { - Write-Host "::error::No PDB files found in symbols folder" + Write-Host "::error::No PDB files found in $uploadPath" Get-ChildItem -Path ./symbols -Recurse | ForEach-Object { Write-Host " Found: $($_.FullName)" } exit 1 } From d781c29d3afb712c9816f4823a1cd66bcfdedf9b Mon Sep 17 00:00:00 2001 From: alves Date: Thu, 4 Dec 2025 14:36:24 +0800 Subject: [PATCH 06/22] feature remove test code --- src/slic3r/GUI/Preferences.cpp | 5 ----- 1 file changed, 5 deletions(-) diff --git a/src/slic3r/GUI/Preferences.cpp b/src/slic3r/GUI/Preferences.cpp index e6accab238..9f6da051dd 100644 --- a/src/slic3r/GUI/Preferences.cpp +++ b/src/slic3r/GUI/Preferences.cpp @@ -1021,11 +1021,6 @@ PreferencesDialog::PreferencesDialog(wxWindow *parent, wxWindowID id, const wxSt : DPIDialog(parent, id, _L("Preferences"), pos, size, style) { SetBackgroundColour(*wxWHITE); - - wxPanel* pPanel = new wxPanel(nullptr); - delete pPanel; - delete pPanel; - create(); wxGetApp().UpdateDlgDarkUI(this); Bind(wxEVT_CLOSE_WINDOW, [this](wxCloseEvent& event) { From 09b8fe5d9af0f9c5b17fef7bca13e99c8242105b Mon Sep 17 00:00:00 2001 From: alves Date: Thu, 4 Dec 2025 17:39:06 +0800 Subject: [PATCH 07/22] feature add api for function report log to server --- CMakeLists.txt | 1 + src/CMakeLists.txt | 14 +- src/Snapmaker_Orca_app_msvc.cpp | 108 +-------------- src/libslic3r/CMakeLists.txt | 9 +- src/sentry_wrapper/SentryWrapper.cpp | 194 +++++++++++++++++++++++++++ src/sentry_wrapper/SentryWrapper.hpp | 30 +++++ src/slic3r/CMakeLists.txt | 6 + src/slic3r/GUI/MainFrame.cpp | 1 + 8 files changed, 257 insertions(+), 106 deletions(-) create mode 100644 src/sentry_wrapper/SentryWrapper.cpp create mode 100644 src/sentry_wrapper/SentryWrapper.hpp diff --git a/CMakeLists.txt b/CMakeLists.txt index d2d90d2521..ceb5ba3ab6 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -99,6 +99,7 @@ option(SLIC3R_MSVC_COMPILE_PARALLEL "Compile on Visual Studio in parallel" 1) option(SLIC3R_MSVC_PDB "Generate PDB files on MSVC in Release mode" 1) option(SLIC3R_PERL_XS "Compile XS Perl module and enable Perl unit and integration tests" 0) option(SLIC3R_ASAN "Enable ASan on Clang and GCC" 0) +option(SLIC3R_SENTRY "Enable Sentry crash reporting" 1) # If SLIC3R_FHS is 1 -> SLIC3R_DESKTOP_INTEGRATION is always 0, othrewise variable. CMAKE_DEPENDENT_OPTION(SLIC3R_DESKTOP_INTEGRATION "Allow perfoming desktop integration during runtime" 1 "NOT SLIC3R_FHS" 0) diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index 7525f6cf45..a1e137b4e5 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -115,7 +115,7 @@ configure_file(${CMAKE_CURRENT_SOURCE_DIR}/dev-utils/platform/msw/Snapmaker_Orca configure_file(${CMAKE_CURRENT_SOURCE_DIR}/dev-utils/platform/msw/Snapmaker_Orca.manifest.in ${CMAKE_CURRENT_BINARY_DIR}/Snapmaker_Orca.manifest @ONLY) configure_file(${CMAKE_CURRENT_SOURCE_DIR}/dev-utils/platform/osx/Info.plist.in ${CMAKE_CURRENT_BINARY_DIR}/Info.plist @ONLY) if (WIN32) - add_library(Snapmaker_Orca SHARED Snapmaker_Orca.cpp Snapmaker_Orca.hpp dev-utils/BaseException.cpp dev-utils/BaseException.h dev-utils/StackWalker.cpp dev-utils/StackWalker.h) + add_library(Snapmaker_Orca SHARED Snapmaker_Orca.cpp Snapmaker_Orca.hpp dev-utils/BaseException.cpp dev-utils/BaseException.h dev-utils/StackWalker.cpp dev-utils/StackWalker.h sentry_wrapper/SentryWrapper.hpp sentry_wrapper/SentryWrapper.cpp) else () add_executable(Snapmaker_Orca Snapmaker_Orca.cpp Snapmaker_Orca.hpp) endif () @@ -168,6 +168,12 @@ target_link_libraries(Snapmaker_Orca libslic3r_gui) #endif () endif () +# Sentry crash reporting integration +if (SLIC3R_SENTRY) + target_compile_definitions(Snapmaker_Orca PUBLIC SLIC3R_SENTRY) + target_link_libraries(Snapmaker_Orca sentry::sentry) +endif() + # On Windows, a shim application is required to produce a console / non console version of the Slic3r application. # Also the shim may load the Mesa software OpenGL renderer if the default renderer does not support OpenGL 2.0 and higher. if (WIN32) @@ -175,7 +181,7 @@ if (WIN32) set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -municode") endif() - add_executable(Snapmaker_Orca_app_gui WIN32 Snapmaker_Orca_app_msvc.cpp ${CMAKE_CURRENT_BINARY_DIR}/Snapmaker_Orca.rc) + add_executable(Snapmaker_Orca_app_gui WIN32 Snapmaker_Orca_app_msvc.cpp sentry_wrapper/SentryWrapper.cpp ${CMAKE_CURRENT_BINARY_DIR}/Snapmaker_Orca.rc) # Generate debug symbols even in release mode. if(MSVC) target_link_options(Snapmaker_Orca_app_gui PUBLIC "$<$:/DEBUG>") @@ -183,7 +189,11 @@ if (WIN32) target_compile_definitions(Snapmaker_Orca_app_gui PRIVATE -DSLIC3R_WRAPPER_NOCONSOLE) add_dependencies(Snapmaker_Orca_app_gui Snapmaker_Orca) set_target_properties(Snapmaker_Orca_app_gui PROPERTIES OUTPUT_NAME "snapmaker-orca") + target_include_directories(Snapmaker_Orca_app_gui PRIVATE ${CMAKE_CURRENT_SOURCE_DIR}) target_link_libraries(Snapmaker_Orca_app_gui PRIVATE boost_headeronly sentry::sentry) + if (SLIC3R_SENTRY) + target_compile_definitions(Snapmaker_Orca_app_gui PRIVATE SLIC3R_SENTRY) + endif() endif () # Link the resources dir to where Slic3r GUI expects it diff --git a/src/Snapmaker_Orca_app_msvc.cpp b/src/Snapmaker_Orca_app_msvc.cpp index 9750c8782c..fe77bf37ea 100644 --- a/src/Snapmaker_Orca_app_msvc.cpp +++ b/src/Snapmaker_Orca_app_msvc.cpp @@ -7,7 +7,7 @@ #include #include #include -#include "sentry.h" +#include "sentry_wrapper/SentryWrapper.hpp" #ifdef SLIC3R_GUI extern "C" { @@ -33,14 +33,7 @@ __declspec(dllexport) int AmdPowerXpressRequestHighPerformance = 0; #include #include -static sentry_value_t on_crash_callback(const sentry_ucontext_t* uctx, sentry_value_t event, void* closure) -{ - (void) uctx; - (void) closure; - - // tell the backend to retain the event - return event; -} +using namespace Slic3r; #ifdef SLIC3R_GUI class OpenGLVersionCheck @@ -218,91 +211,6 @@ typedef int(__stdcall* Slic3rMainFunc)(int argc, wchar_t** argv); Slic3rMainFunc Snapmaker_Orca_main = nullptr; } -void initSentry() -{ - sentry_options_t* options = sentry_options_new(); - { -#ifdef WIN32 - std::string dsn = std::string("https://c74b617c2aedc291444d3a238d23e780@o4508125599563776.ingest.us.sentry.io/4510425163956224"); - - sentry_options_set_dsn(options, dsn.c_str()); - - wchar_t exeDir[MAX_PATH]; - ::GetModuleFileNameW(nullptr, exeDir, MAX_PATH); - std::wstring wsExeDir(exeDir); - int nPos = wsExeDir.find_last_of('\\'); - std::wstring wsDmpDir = wsExeDir.substr(0, nPos + 1); - - std::wstring handlerDir = wsDmpDir + L"crashpad_handler.exe"; - wsDmpDir += L"dump"; - - auto wstringTostring = [](std::wstring wTmpStr) -> std::string { - std::string resStr = std::string(); - int len = WideCharToMultiByte(CP_UTF8, 0, wTmpStr.c_str(), -1, nullptr, 0, nullptr, nullptr); - - if (len <= 0) - return std::string(); - std::string desStr(len, 0); - - WideCharToMultiByte(CP_UTF8, 0, wTmpStr.c_str(), -1, &desStr[0], len, nullptr, nullptr); - - resStr = desStr; - - return resStr; - }; - - std::string desDir = wstringTostring(handlerDir); - if (!desDir.empty()) - sentry_options_set_handler_path(options, desDir.c_str()); - desDir = wstringTostring(wsDmpDir); - desDir = wstringTostring(wsDmpDir); - wchar_t appDataPath[MAX_PATH] = {0}; - auto hr = SHGetFolderPathW(NULL, CSIDL_LOCAL_APPDATA, NULL, SHGFP_TYPE_CURRENT, appDataPath); - char* path = new char[MAX_PATH]; - size_t pathLength; - wcstombs_s(&pathLength, path, MAX_PATH, appDataPath, MAX_PATH); - std::string filePath = path; - std::string appName = "\\" + std::string("Snapmaker_Orca\\"); - filePath = filePath + appName; - - if (!filePath.empty()) - sentry_options_set_database_path(options, filePath.c_str()); -#endif - std::string softVersion = "snapmaker_orca_2.2.0_beta2"; - // Snapmaker_VERSION - sentry_options_set_release(options, softVersion.c_str()); - -#if defined(_DEBUG) || !defined(NDEBUG) - sentry_options_set_debug(options, 1); -#else - sentry_options_set_debug(options, 0); -#endif - // release version environment(Testing/production/development/Staging) - sentry_options_set_environment(options, "develop"); - sentry_options_set_auto_session_tracking(options, false); - sentry_options_set_symbolize_stacktraces(options, true); - sentry_options_set_on_crash(options, on_crash_callback, NULL); - // Enable before_send hook for filtering sensitive data - sentry_options_set_before_send(options, NULL, NULL); - - // Ensure all events and crashes are captured (sample rate 100%) - sentry_options_set_sample_rate(options, 1.0); // Capture 100% of events - sentry_options_set_traces_sample_rate(options, 1.0); // Capture 100% of traces - - sentry_init(options); - sentry_start_session(); - - DWORD processID = GetCurrentProcessId(); - sentry_set_tag("PID", std::to_string(processID).c_str()); - - auto pcName = boost::asio::ip::host_name(); - // auto macAddress = getMacAddress(); - - sentry_set_tag("computer_name", pcName.c_str()); - // sentry_set_tag("mac_address", macAddress.c_str()); - } -} - extern "C" { #ifdef SLIC3R_WRAPPER_NOCONSOLE int APIENTRY wWinMain(HINSTANCE /* hInstance */, HINSTANCE /* hPrevInstance */, PWSTR /* lpCmdLine */, int /* nCmdShow */) @@ -318,16 +226,10 @@ int wmain(int argc, wchar_t** argv) // the application will be killed even if "Ignore" button is pressed. _set_error_mode(_OUT_TO_MSGBOX); -#if defined(_DEBUG) || !defined(NDEBUG) - SetUnhandledExceptionFilter((LPTOP_LEVEL_EXCEPTION_FILTER) ExceptionCrashHandler); -#else - // Initialize Sentry for crash reporting in Release builds initSentry(); -#endif std::vector argv_extended; argv_extended.emplace_back(argv[0]); - #ifdef SLIC3R_WRAPPER_GCODEVIEWER wchar_t gcodeviewer_param[] = L"--gcodeviewer"; argv_extended.emplace_back(gcodeviewer_param); @@ -390,7 +292,7 @@ int wmain(int argc, wchar_t** argv) HINSTANCE hInstance_Slic3r = LoadLibraryExW(path_to_slic3r, nullptr, 0); if (hInstance_Slic3r == nullptr) { printf("Snapmaker_Orca.dll was not loaded, error=%d\n", GetLastError()); - sentry_close(); + exitSentry(); return -1; } @@ -406,13 +308,13 @@ int wmain(int argc, wchar_t** argv) ); if (Snapmaker_Orca_main == nullptr) { printf("could not locate the function Snapmaker_Orca_main in Snapmaker_Orca.dll\n"); - sentry_close(); + exitSentry(); return -1; } // argc minus the trailing nullptr of the argv auto res = Snapmaker_Orca_main((int) argv_extended.size() - 1, argv_extended.data()); - sentry_close(); + exitSentry(); return res; } } diff --git a/src/libslic3r/CMakeLists.txt b/src/libslic3r/CMakeLists.txt index d85c65fd51..7ddad94f1d 100644 --- a/src/libslic3r/CMakeLists.txt +++ b/src/libslic3r/CMakeLists.txt @@ -511,7 +511,8 @@ endif () encoding_check(libslic3r) target_compile_definitions(libslic3r PUBLIC -DUSE_TBB -DTBB_USE_CAPTURED_EXCEPTION=0) -target_include_directories(libslic3r PRIVATE ${CMAKE_CURRENT_SOURCE_DIR} PUBLIC ${CMAKE_CURRENT_BINARY_DIR}) +# Make source directory PUBLIC so other modules (like libslic3r_gui) can include headers like SentryWrapper.hpp +target_include_directories(libslic3r PUBLIC ${CMAKE_CURRENT_SOURCE_DIR} ${CMAKE_CURRENT_BINARY_DIR}) target_include_directories(libslic3r SYSTEM PUBLIC ${EXPAT_INCLUDE_DIRS}) # Find the OCCT and related libraries @@ -610,3 +611,9 @@ endif() if (SLIC3R_PCH AND NOT SLIC3R_SYNTAXONLY) add_precompiled_header(libslic3r pchheader.hpp FORCEINCLUDE) endif () + +# Sentry crash reporting integration +if (SLIC3R_SENTRY) + target_compile_definitions(libslic3r PUBLIC SLIC3R_SENTRY) + target_link_libraries(libslic3r PUBLIC sentry::sentry) +endif() diff --git a/src/sentry_wrapper/SentryWrapper.cpp b/src/sentry_wrapper/SentryWrapper.cpp new file mode 100644 index 0000000000..1103fbb420 --- /dev/null +++ b/src/sentry_wrapper/SentryWrapper.cpp @@ -0,0 +1,194 @@ +/** + * @file SentryWrapper.cpp + * @brief Sentry crash reporting wrapper implementation for cross-platform support. + * + * This implementation provides a unified API for Sentry integration. + * When SLIC3R_SENTRY is not defined, all functions become no-ops. + */ + +#include "SentryWrapper.hpp" + +#ifdef SLIC3R_SENTRY +#include "sentry.h" + +#ifdef _WIN32 +#include +#include +#endif + +#endif + +#include + +namespace Slic3r { + +#ifdef SLIC3R_SENTRY + +static sentry_value_t on_crash_callback(const sentry_ucontext_t* uctx, sentry_value_t event, void* closure) +{ + (void) uctx; + (void) closure; + + // tell the backend to retain the event + return event; +} + +void initSentryEx() +{ + sentry_options_t* options = sentry_options_new(); + { +#ifdef WIN32 + std::string dsn = std::string("https://c74b617c2aedc291444d3a238d23e780@o4508125599563776.ingest.us.sentry.io/4510425163956224"); + + sentry_options_set_dsn(options, dsn.c_str()); + + wchar_t exeDir[MAX_PATH]; + ::GetModuleFileNameW(nullptr, exeDir, MAX_PATH); + std::wstring wsExeDir(exeDir); + int nPos = wsExeDir.find_last_of('\\'); + std::wstring wsDmpDir = wsExeDir.substr(0, nPos + 1); + + std::wstring handlerDir = wsDmpDir + L"crashpad_handler.exe"; + wsDmpDir += L"dump"; + + auto wstringTostring = [](std::wstring wTmpStr) -> std::string { + std::string resStr = std::string(); + int len = WideCharToMultiByte(CP_UTF8, 0, wTmpStr.c_str(), -1, nullptr, 0, nullptr, nullptr); + + if (len <= 0) + return std::string(); + std::string desStr(len, 0); + + WideCharToMultiByte(CP_UTF8, 0, wTmpStr.c_str(), -1, &desStr[0], len, nullptr, nullptr); + + resStr = desStr; + + return resStr; + }; + + std::string desDir = wstringTostring(handlerDir); + if (!desDir.empty()) + sentry_options_set_handler_path(options, desDir.c_str()); + desDir = wstringTostring(wsDmpDir); + desDir = wstringTostring(wsDmpDir); + wchar_t appDataPath[MAX_PATH] = {0}; + auto hr = SHGetFolderPathW(NULL, CSIDL_LOCAL_APPDATA, NULL, SHGFP_TYPE_CURRENT, appDataPath); + char* path = new char[MAX_PATH]; + size_t pathLength; + wcstombs_s(&pathLength, path, MAX_PATH, appDataPath, MAX_PATH); + std::string filePath = path; + std::string appName = "\\" + std::string("Snapmaker_Orca\\"); + filePath = filePath + appName; + + if (!filePath.empty()) + sentry_options_set_database_path(options, filePath.c_str()); +#endif + std::string softVersion = "snapmaker_orca_2.2.0_beta2"; + // Snapmaker_VERSION + sentry_options_set_release(options, softVersion.c_str()); + +#if defined(_DEBUG) || !defined(NDEBUG) + sentry_options_set_debug(options, 1); +#else + sentry_options_set_debug(options, 0); +#endif + // release version environment(Testing/production/development/Staging) + sentry_options_set_environment(options, "develop"); + sentry_options_set_auto_session_tracking(options, false); + sentry_options_set_symbolize_stacktraces(options, true); + sentry_options_set_on_crash(options, on_crash_callback, NULL); + // Enable before_send hook for filtering sensitive data + sentry_options_set_before_send(options, NULL, NULL); + + // Ensure all events and crashes are captured (sample rate 100%) + sentry_options_set_sample_rate(options, 1.0); // Capture 100% of events + sentry_options_set_traces_sample_rate(options, 1.0); // Capture 100% of traces + + sentry_init(options); + sentry_start_session(); + } +} + +void exitSentryEx() +{ + sentry_close(); +} +void sentryReportLogEx(SENTRY_LOG_LEVEL logLevel, + const std::string& logContent, + const std::string& funcModule, + const std::string& logTagKey, + const std::string& logTagValue, + const std::string& logTraceId) +{ + sentry_level_t sentry_msg_level; + switch (logLevel) + { + case SENTRY_LOG_TRACE: + sentry_msg_level = SENTRY_LEVEL_TRACE; + break; + case SENTRY_LOG_DEBUG: + sentry_msg_level = SENTRY_LEVEL_DEBUG; + break; + case SENTRY_LOG_INFO: + sentry_msg_level = SENTRY_LEVEL_INFO; + break; + case SENTRY_LOG_WARNING: + sentry_msg_level = SENTRY_LEVEL_WARNING; + break; + case SENTRY_LOG_ERROR: + sentry_msg_level = SENTRY_LEVEL_ERROR; + break; + case SENTRY_LOG_FATAL: + sentry_msg_level = SENTRY_LEVEL_FATAL; + break; + default: + return; + } + + sentry_value_t event = sentry_value_new_message_event(sentry_msg_level, + funcModule.c_str(), + logContent.c_str() + ); + + if (!logTraceId.empty()) + sentry_set_trace(logTraceId.c_str(), ""); + + if (!logTagKey.empty()) + sentry_set_tag(logTagKey.c_str(), logTagValue.c_str()); + + sentry_capture_event(event); +} + + +#else // SLIC3R_SENTRY not defined - provide no-op implementations + + +#endif // SLIC3R_SENTRY + +void initSentry() +{ +#ifdef SLIC3R_SENTRY + initSentryEx(); +#endif +} + +void exitSentry() +{ +#ifdef SLIC3R_SENTRY + exitSentryEx(); +#endif +} +void sentryReportLog(SENTRY_LOG_LEVEL logLevel, + const std::string& logContent, + const std::string& funcModule, + const std::string& logTagKey, + const std::string& logTagValue, + const std::string& logTraceId) +{ +#ifdef SLIC3R_SENTRY + sentryReportLogEx(logLevel, logContent, funcModule, logTagKey, logTagValue, logTraceId); +#endif +} + +} // namespace Slic3r + diff --git a/src/sentry_wrapper/SentryWrapper.hpp b/src/sentry_wrapper/SentryWrapper.hpp new file mode 100644 index 0000000000..32f46f210d --- /dev/null +++ b/src/sentry_wrapper/SentryWrapper.hpp @@ -0,0 +1,30 @@ +#ifndef slic3r_SentryWrapper_hpp_ +#define slic3r_SentryWrapper_hpp_ + +#include + +namespace Slic3r { + + void initSentry(); + + void exitSentry(); + + typedef enum SENTRY_LOG_LEVEL { + SENTRY_LOG_TRACE = -2, + SENTRY_LOG_DEBUG = -1, + SENTRY_LOG_INFO = 0, + SENTRY_LOG_WARNING = 1, + SENTRY_LOG_ERROR = 2, + SENTRY_LOG_FATAL = 3, + }; + + void sentryReportLog(SENTRY_LOG_LEVEL logLevel, + const std::string& logContent, + const std::string& funcModule = "", + const std::string& logTagKey = "", + const std::string& logTagValue = "", + const std::string& logTraceId = ""); + } // namespace Slic3r + +#endif // slic3r_SentryWrapper_hpp_ + diff --git a/src/slic3r/CMakeLists.txt b/src/slic3r/CMakeLists.txt index 5f6584ceaa..44ae2d49a1 100644 --- a/src/slic3r/CMakeLists.txt +++ b/src/slic3r/CMakeLists.txt @@ -737,3 +737,9 @@ endif () # Add a definition so that we can tell we are compiling slic3r. target_compile_definitions(libslic3r_gui PRIVATE SLIC3R_CURRENTLY_COMPILING_GUI_MODULE) + +# Sentry crash reporting integration +if (SLIC3R_SENTRY) + target_compile_definitions(libslic3r_gui PUBLIC SLIC3R_SENTRY) + target_link_libraries(libslic3r_gui sentry::sentry) +endif() \ No newline at end of file diff --git a/src/slic3r/GUI/MainFrame.cpp b/src/slic3r/GUI/MainFrame.cpp index 15b9856903..8a42c4747e 100644 --- a/src/slic3r/GUI/MainFrame.cpp +++ b/src/slic3r/GUI/MainFrame.cpp @@ -72,6 +72,7 @@ #include #include #include +#include "sentry_wrapper/SentryWrapper.hpp" #endif // _WIN32 #include From 70fa560264734893396d0b3766c62e51534915a4 Mon Sep 17 00:00:00 2001 From: alves Date: Thu, 4 Dec 2025 17:48:32 +0800 Subject: [PATCH 08/22] feature update the soft version --- .github/workflows/build_all.yml | 2 +- .github/workflows/build_orca.yml | 12 ++++++------ 2 files changed, 7 insertions(+), 7 deletions(-) diff --git a/.github/workflows/build_all.yml b/.github/workflows/build_all.yml index 640f110c43..2fe102dbe1 100644 --- a/.github/workflows/build_all.yml +++ b/.github/workflows/build_all.yml @@ -151,7 +151,7 @@ jobs: if-no-files-found: error - name: Deploy Flatpak to nightly release - if: ${{github.ref == 'refs/heads/main' || github.ref == 'refs/heads/2.2.0'}} + if: ${{github.ref == 'refs/heads/main' || github.ref == 'refs/heads/2.2.1'}} uses: WebFreak001/deploy-nightly@v3.2.0 with: upload_url: https://uploads.github.com/repos/Snapmaker/OrcaSlicer/releases/169912305/assets{?name,label} diff --git a/.github/workflows/build_orca.yml b/.github/workflows/build_orca.yml index 7f6fcd4eef..b9411fd28d 100644 --- a/.github/workflows/build_orca.yml +++ b/.github/workflows/build_orca.yml @@ -306,7 +306,7 @@ jobs: path: ${{ github.workspace }}/build/src/Release/Snapmaker_Orca_profile_validator.exe - name: Deploy Windows release portable - if: (github.ref == 'refs/heads/main' || github.ref == 'refs/heads/2.2.0') && inputs.os == 'windows-latest' + if: (github.ref == 'refs/heads/main' || github.ref == 'refs/heads/2.2.1') && inputs.os == 'windows-latest' uses: WebFreak001/deploy-nightly@v3.2.0 with: upload_url: https://uploads.github.com/repos/Snapmaker/OrcaSlicer/releases/169912305/assets{?name,label} @@ -317,7 +317,7 @@ jobs: max_releases: 1 - name: Deploy Windows release installer - if: (github.ref == 'refs/heads/main' || github.ref == 'refs/heads/2.2.0') && inputs.os == 'windows-latest' + if: (github.ref == 'refs/heads/main' || github.ref == 'refs/heads/2.2.1') && inputs.os == 'windows-latest' uses: WebFreak001/deploy-nightly@v3.2.0 with: upload_url: https://uploads.github.com/repos/Snapmaker/OrcaSlicer/releases/169912305/assets{?name,label} @@ -328,7 +328,7 @@ jobs: max_releases: 1 - name: Deploy Windows Snapmaker_Orca_profile_validator release - if: (github.ref == 'refs/heads/main' || github.ref == 'refs/heads/2.2.0') && inputs.os == 'windows-latest' + if: (github.ref == 'refs/heads/main' || github.ref == 'refs/heads/2.2.1') && inputs.os == 'windows-latest' uses: WebFreak001/deploy-nightly@v3.2.0 with: upload_url: https://uploads.github.com/repos/Snapmaker/OrcaSlicer/releases/169912305/assets{?name,label} @@ -402,7 +402,7 @@ jobs: path: './build/src/Release/Snapmaker_Orca_profile_validator' - name: Deploy Ubuntu release - if: ${{ ! env.ACT && (github.ref == 'refs/heads/main' || github.ref == 'refs/heads/2.2.0') && (inputs.os == 'ubuntu-20.04' || inputs.os == 'ubuntu-24.04') }} + if: ${{ ! env.ACT && (github.ref == 'refs/heads/main' || github.ref == 'refs/heads/2.2.1') && (inputs.os == 'ubuntu-20.04' || inputs.os == 'ubuntu-24.04') }} env: ubuntu-ver-str: ${{ (inputs.os == 'ubuntu-24.04' && '_Ubuntu2404') || '' }} uses: WebFreak001/deploy-nightly@v3.2.0 @@ -423,7 +423,7 @@ jobs: message: "nightly-builds" - name: Deploy Ubuntu Snapmaker_Orca_profile_validator release - if: ${{ ! env.ACT && (github.ref == 'refs/heads/main' || github.ref == 'refs/heads/2.2.0') && (inputs.os == 'ubuntu-20.04' || inputs.os == 'ubuntu-24.04') }} + if: ${{ ! env.ACT && (github.ref == 'refs/heads/main' || github.ref == 'refs/heads/2.2.1') && (inputs.os == 'ubuntu-20.04' || inputs.os == 'ubuntu-24.04') }} env: ubuntu-ver-str: ${{ (inputs.os == 'ubuntu-24.04' && '_Ubuntu2404') || '' }} uses: WebFreak001/deploy-nightly@v3.2.0 @@ -436,7 +436,7 @@ jobs: max_releases: 1 - name: Deploy orca_custom_preset_tests - if: ${{ ! env.ACT && (github.ref == 'refs/heads/main' || github.ref == 'refs/heads/2.2.0') && inputs.os == 'ubuntu-24.04' }} + if: ${{ ! env.ACT && (github.ref == 'refs/heads/main' || github.ref == 'refs/heads/2.2.1') && inputs.os == 'ubuntu-24.04' }} uses: WebFreak001/deploy-nightly@v3.2.0 with: upload_url: https://uploads.github.com/repos/Snapmaker/OrcaSlicer/releases/169912305/assets{?name,label} From 51ec64470e200dec51580dc92bcd7158048c100e Mon Sep 17 00:00:00 2001 From: alves Date: Fri, 5 Dec 2025 13:06:46 +0800 Subject: [PATCH 09/22] feature merge mac sentry to win platform. --- CMakeLists.txt | 19 ++++++- build_release_vs2022.bat | 2 +- deps/CMakeLists.txt | 8 --- deps/Sentry/Sentry.cmake | 58 +++++++++++++++++++--- src/CMakeLists.txt | 29 ++++++++++- src/Snapmaker_Orca.cpp | 12 ++++- src/sentry_wrapper/SentryWrapper.cpp | 74 +++++++++++++++++++--------- src/sentry_wrapper/SentryWrapper.hpp | 2 +- src/slic3r/GUI/Preferences.cpp | 5 ++ 9 files changed, 163 insertions(+), 46 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 13642a8cb2..d461af3025 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -543,7 +543,12 @@ find_package(TBB REQUIRED) find_package(OpenSSL REQUIRED) find_package(CURL REQUIRED) if (SLIC3R_SENTRY) - find_package(Sentry REQUIRED) + find_package(Sentry QUIET) + if (NOT Sentry_FOUND) + message(WARNING "Sentry SDK not found. SLIC3R_SENTRY will be disabled. " + "Build deps with Sentry support or use -DSLIC3R_SENTRY=OFF") + set(SLIC3R_SENTRY OFF CACHE BOOL "Enable Sentry crash reporting SDK" FORCE) + endif() endif() find_package(Freetype REQUIRED) @@ -569,7 +574,17 @@ if (SLIC3R_SENTRY) else() message(WARNING "sentry.lib not found in ${CMAKE_PREFIX_PATH}/lib. Sentry SDK may not have been built yet.") endif() - endif() + elseif (APPLE AND CMAKE_PREFIX_PATH) + # Try to find libsentry.dylib in the install prefix for macOS + file(GLOB _sentry_lib "${CMAKE_PREFIX_PATH}/lib/libsentry.dylib") + if (_sentry_lib) + target_link_directories(sentry INTERFACE "${CMAKE_PREFIX_PATH}/lib") + target_link_libraries(sentry INTERFACE "sentry") + message(STATUS "Found libsentry.dylib at: ${CMAKE_PREFIX_PATH}/lib") + else() + message(WARNING "libsentry.dylib not found in ${CMAKE_PREFIX_PATH}/lib. Sentry SDK may not have been built yet.") + endif() + endif() endif() # Fixing curl's cmake config script bugs diff --git a/build_release_vs2022.bat b/build_release_vs2022.bat index 488f02fe07..2724bf876f 100644 --- a/build_release_vs2022.bat +++ b/build_release_vs2022.bat @@ -47,7 +47,7 @@ if "%1"=="slicer" ( echo "building deps.." echo on -cmake ../ -G "Visual Studio 17 2022" -A x64 -DDESTDIR="%DEPS%" -DCMAKE_BUILD_TYPE=%build_type% -DDEP_DEBUG=%debug% -DORCA_INCLUDE_DEBUG_INFO=%debuginfo% +cmake ../ -G "Visual Studio 17 2022" -A x64 -DDESTDIR="%DEPS%" -DCMAKE_BUILD_TYPE=%build_type% -DDEP_DEBUG=%debug% -DORCA_INCLUDE_DEBUG_INFO=%debuginfo% -DSLIC3R_SENTRY=ON cmake --build . --config %build_type% --target deps -- -m @echo off diff --git a/deps/CMakeLists.txt b/deps/CMakeLists.txt index de9fae0bc5..126da82e8c 100644 --- a/deps/CMakeLists.txt +++ b/deps/CMakeLists.txt @@ -62,14 +62,6 @@ if(CMAKE_SYSTEM_NAME STREQUAL "Linux") option(DEP_WX_GTK3 "Build wxWidgets against GTK3" OFF) endif() -# Sentry crash reporting - enabled only on Windows by default -if (WIN32) - set(SLIC3R_SENTRY_DEFAULT ON) -else() - set(SLIC3R_SENTRY_DEFAULT OFF) -endif() -option(SLIC3R_SENTRY "Enable Sentry crash reporting SDK" ${SLIC3R_SENTRY_DEFAULT}) - set(IS_CROSS_COMPILE FALSE) if (APPLE) diff --git a/deps/Sentry/Sentry.cmake b/deps/Sentry/Sentry.cmake index 91e49fc74b..f636281dbe 100644 --- a/deps/Sentry/Sentry.cmake +++ b/deps/Sentry/Sentry.cmake @@ -2,7 +2,7 @@ set(_sentry_platform_flags -DCMAKE_POSITION_INDEPENDENT_CODE=ON -DSENTRY_BUILD_TESTS=OFF -DSENTRY_EXAMPLES=OFF - -DSENTRY_CRASHPAD_BACKEND=ON + -DSENTRY_BACKEND=crashpad -DSENTRY_ENABLE_INSTALL=ON ) @@ -25,16 +25,35 @@ if (WIN32) set(_sentry_cmake_generator -G "Visual Studio 17 2022") endif() elseif (APPLE) - # macOS: Use Unix Makefiles (install will put libs in ${DESTDIR}/bin or lib) + # macOS: build shared libs so we get libsentry.dylib + # Note: CURL transport requires OpenSSL, need to link it explicitly + # DESTDIR already contains /usr/local/ suffix, so use it directly set(_sentry_platform_flags ${_sentry_platform_flags} -DSENTRY_TRANSPORT_CURL=ON - -DSENTRY_BUILD_SHARED_LIBS=OFF + -DSENTRY_BUILD_SHARED_LIBS=ON -DCMAKE_BUILD_TYPE:STRING=RelWithDebInfo - -DCMAKE_C_FLAGS:STRING=-g -O2 - -DCMAKE_CXX_FLAGS:STRING=-g -O2 + -DOPENSSL_ROOT_DIR:PATH=${DESTDIR} + -DOPENSSL_USE_STATIC_LIBS:BOOL=ON + -DCMAKE_SHARED_LINKER_FLAGS:STRING=-L${DESTDIR}/lib\ -lssl\ -lcrypto ) set(_sentry_cmake_generator -G "Unix Makefiles") + + # Sentry/crashpad requires macOS 12.0+ due to kIOMainPortDefault API usage + # Force minimum deployment target to 12.0 for Sentry build + set(_sentry_osx_deployment_target "12.0") + if (CMAKE_OSX_DEPLOYMENT_TARGET AND CMAKE_OSX_DEPLOYMENT_TARGET VERSION_GREATER "12.0") + set(_sentry_osx_deployment_target ${CMAKE_OSX_DEPLOYMENT_TARGET}) + endif() + + # Add macOS architecture and deployment target for sentry build + if (CMAKE_OSX_ARCHITECTURES) + set(_sentry_platform_flags ${_sentry_platform_flags} -DCMAKE_OSX_ARCHITECTURES:STRING=${CMAKE_OSX_ARCHITECTURES}) + endif() + set(_sentry_platform_flags ${_sentry_platform_flags} -DCMAKE_OSX_DEPLOYMENT_TARGET:STRING=${_sentry_osx_deployment_target}) + if (CMAKE_OSX_SYSROOT) + set(_sentry_platform_flags ${_sentry_platform_flags} -DCMAKE_OSX_SYSROOT:STRING=${CMAKE_OSX_SYSROOT}) + endif() elseif(CMAKE_SYSTEM_NAME STREQUAL "Linux") # Linux: Use Unix Makefiles set(_sentry_platform_flags @@ -42,22 +61,45 @@ elseif(CMAKE_SYSTEM_NAME STREQUAL "Linux") -DSENTRY_TRANSPORT_CURL=ON -DSENTRY_BUILD_SHARED_LIBS=OFF -DCMAKE_BUILD_TYPE:STRING=RelWithDebInfo - -DCMAKE_C_FLAGS:STRING=-g -O2 - -DCMAKE_CXX_FLAGS:STRING=-g -O2 ) set(_sentry_cmake_generator -G "Unix Makefiles") endif () +if(WIN32) + set(SENTRY_PATCH_COMMAND + ${GIT_EXECUTABLE} submodule update --init --recursive && ${CMAKE_COMMAND} -S external/crashpad -B external/crashpad/build ${_sentry_cmake_generator} -DCMAKE_BUILD_TYPE=Release && ${CMAKE_COMMAND} --build external/crashpad/build --config Release + ) +elseif(APPLE) + set(SENTRY_PATCH_COMMAND + ${GIT_EXECUTABLE} submodule update --init --recursive + ) +else() + set(SENTRY_PATCH_COMMAND + ${GIT_EXECUTABLE} submodule update --init --recursive + ) +endif() + Snapmaker_Orca_add_cmake_project(Sentry GIT_REPOSITORY https://github.com/getsentry/sentry-native.git GIT_TAG 0.12.1 - PATCH_COMMAND ${GIT_EXECUTABLE} submodule update --init --recursive && ${CMAKE_COMMAND} -S external/crashpad -B external/crashpad/build ${_sentry_cmake_generator} -DCMAKE_BUILD_TYPE=Release && ${CMAKE_COMMAND} --build external/crashpad/build --config Release + PATCH_COMMAND ${SENTRY_PATCH_COMMAND} CMAKE_ARGS ${_sentry_cmake_generator} -DCMAKE_INSTALL_DATADIR:STRING=share ${_sentry_platform_flags} ) +# Sentry depends on CURL which depends on OpenSSL +# Ensure they are built before Sentry +if(APPLE) + if (TARGET dep_CURL) + add_dependencies(dep_Sentry dep_CURL) + endif() + if (TARGET dep_OpenSSL) + add_dependencies(dep_Sentry dep_OpenSSL) + endif() +endif() + if (MSVC) add_debug_dep(dep_Sentry) endif () diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index ca9e209e0c..2e07f3929a 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -117,7 +117,7 @@ configure_file(${CMAKE_CURRENT_SOURCE_DIR}/dev-utils/platform/osx/Info.plist.in if (WIN32) add_library(Snapmaker_Orca SHARED Snapmaker_Orca.cpp Snapmaker_Orca.hpp dev-utils/BaseException.cpp dev-utils/BaseException.h dev-utils/StackWalker.cpp dev-utils/StackWalker.h sentry_wrapper/SentryWrapper.hpp sentry_wrapper/SentryWrapper.cpp) else () - add_executable(Snapmaker_Orca Snapmaker_Orca.cpp Snapmaker_Orca.hpp) + add_executable(Snapmaker_Orca Snapmaker_Orca.cpp Snapmaker_Orca.hpp sentry_wrapper/SentryWrapper.hpp sentry_wrapper/SentryWrapper.cpp) endif () if (MINGW) @@ -159,6 +159,8 @@ target_link_libraries(Snapmaker_Orca libslic3r_gui) target_link_libraries(Snapmaker_Orca ws2_32 uxtheme setupapi) elseif (APPLE) target_link_libraries(Snapmaker_Orca "-framework OpenGL") + # Link Sentry for crash reporting on macOS + target_link_libraries(Snapmaker_Orca sentry::sentry) else () target_link_libraries(Snapmaker_Orca -ldl) endif () @@ -246,6 +248,16 @@ else () COMMAND ln -sf Snapmaker_Orca snapmaker-orca WORKING_DIRECTORY "$" VERBATIM) + # Copy Sentry crashpad_handler to executable directory for non-bundle builds (e.g., Xcode debugging) + add_custom_command(TARGET Snapmaker_Orca POST_BUILD + COMMAND sh -c "if [ -f '${CMAKE_PREFIX_PATH}/bin/crashpad_handler' ]; then cp -f '${CMAKE_PREFIX_PATH}/bin/crashpad_handler' '$/crashpad_handler' && codesign --force --sign - '$/crashpad_handler' 2>/dev/null || true; fi" + COMMENT "Copying crashpad_handler for Sentry crash reporting" + VERBATIM) + # Copy libsentry.dylib to executable directory for non-bundle builds + add_custom_command(TARGET Snapmaker_Orca POST_BUILD + COMMAND sh -c "if [ -f '${CMAKE_PREFIX_PATH}/lib/libsentry.dylib' ]; then cp -f '${CMAKE_PREFIX_PATH}/lib/libsentry.dylib' '$/libsentry.dylib' && codesign --force --sign - '$/libsentry.dylib' 2>/dev/null || true; fi" + COMMENT "Copying libsentry.dylib for Sentry crash reporting" + VERBATIM) else () add_custom_command(TARGET Snapmaker_Orca POST_BUILD WORKING_DIRECTORY "$" @@ -278,6 +290,21 @@ else () COMMAND ${CMAKE_COMMAND} -E create_symlink "${SLIC3R_RESOURCES_DIR}" "$/../Resources" COMMENT "Symlinking the resources directory into the build tree" VERBATIM) + # Copy Sentry crashpad_handler to MacOS directory (same directory as executable) + add_custom_command(TARGET Snapmaker_Orca POST_BUILD + COMMAND sh -c "if [ -f '${CMAKE_PREFIX_PATH}/bin/crashpad_handler' ]; then cp -f '${CMAKE_PREFIX_PATH}/bin/crashpad_handler' '$/crashpad_handler' && codesign --force --sign - '$/crashpad_handler'; fi" + COMMENT "Copying and signing crashpad_handler for Sentry crash reporting" + VERBATIM) + # Copy libsentry.dylib to Frameworks directory + add_custom_command(TARGET Snapmaker_Orca POST_BUILD + COMMAND sh -c "if [ -f '${CMAKE_PREFIX_PATH}/lib/libsentry.dylib' ]; then mkdir -p '$/../Frameworks' && cp -f '${CMAKE_PREFIX_PATH}/lib/libsentry.dylib' '$/../Frameworks/libsentry.dylib' && codesign --force --sign - '$/../Frameworks/libsentry.dylib'; fi" + COMMENT "Copying and signing libsentry.dylib for Sentry crash reporting" + VERBATIM) + # Update the rpath for libsentry.dylib + add_custom_command(TARGET Snapmaker_Orca POST_BUILD + COMMAND install_name_tool -change "@rpath/libsentry.dylib" "@executable_path/../Frameworks/libsentry.dylib" "$" || true + COMMENT "Updating rpath for libsentry.dylib" + VERBATIM) endif() endif () diff --git a/src/Snapmaker_Orca.cpp b/src/Snapmaker_Orca.cpp index 60176d5c3a..1b1c197a4f 100644 --- a/src/Snapmaker_Orca.cpp +++ b/src/Snapmaker_Orca.cpp @@ -33,6 +33,10 @@ using namespace nlohmann; #endif +#ifdef SLIC3R_SENTRY +#include "sentry_wrapper/SentryWrapper.hpp" +#endif + #include #include #include @@ -6291,6 +6295,12 @@ extern "C" { #else /* _MSC_VER */ int main(int argc, char **argv) { - return CLI().run(argc, argv); + initSentry(); + + auto res = CLI().run(argc, argv); + + exitSentry(); + + return res; } #endif /* _MSC_VER */ diff --git a/src/sentry_wrapper/SentryWrapper.cpp b/src/sentry_wrapper/SentryWrapper.cpp index 1103fbb420..613ca3dda4 100644 --- a/src/sentry_wrapper/SentryWrapper.cpp +++ b/src/sentry_wrapper/SentryWrapper.cpp @@ -10,14 +10,19 @@ #ifdef SLIC3R_SENTRY #include "sentry.h" +#endif #ifdef _WIN32 #include #include #endif +#ifdef __APPLE__ +#include +#include #endif +#include #include namespace Slic3r { @@ -36,41 +41,60 @@ static sentry_value_t on_crash_callback(const sentry_ucontext_t* uctx, sentry_va void initSentryEx() { sentry_options_t* options = sentry_options_new(); + std::string dsn = ""; { -#ifdef WIN32 +#ifdef __APPLE__ + + std::string dsn = std::string("https://ac473187efb8877f36bd31694ffd5dec@o4508125599563776.ingest.us.sentry.io/4510425212059648"); + +#elif _WIN32 std::string dsn = std::string("https://c74b617c2aedc291444d3a238d23e780@o4508125599563776.ingest.us.sentry.io/4510425163956224"); - +#endif sentry_options_set_dsn(options, dsn.c_str()); + std::string handlerDir = ""; + std::string dataBaseDir = ""; +#ifdef __APPLE__ + + char exe_path[PATH_MAX] = {0}; + uint32_t buf_size = PATH_MAX; + + if (_NSGetExecutablePath(exe_path, &buf_size) != 0) { + throw std::runtime_error("Buffer too small for executable path"); + } + + // Get the directory containing the executable, not the executable path itself + boost::filesystem::path exe_dir = boost::filesystem::path(exe_path).parent_path(); + handlerDir = (exe_dir / "crashpad_handler").string(); + + const char* home_env = getenv("HOME"); + + dataBaseDir = home_env; + dataBaseDir = dataBaseDir + "/Library/Application Support/Snapmaker_Orca/SentryData"; +#elif _WIN32 wchar_t exeDir[MAX_PATH]; ::GetModuleFileNameW(nullptr, exeDir, MAX_PATH); std::wstring wsExeDir(exeDir); int nPos = wsExeDir.find_last_of('\\'); std::wstring wsDmpDir = wsExeDir.substr(0, nPos + 1); - - std::wstring handlerDir = wsDmpDir + L"crashpad_handler.exe"; + std::wstring desDir = wsDmpDir + L"crashpad_handler.exe"; wsDmpDir += L"dump"; auto wstringTostring = [](std::wstring wTmpStr) -> std::string { std::string resStr = std::string(); int len = WideCharToMultiByte(CP_UTF8, 0, wTmpStr.c_str(), -1, nullptr, 0, nullptr, nullptr); - if (len <= 0) return std::string(); + std::string desStr(len, 0); - WideCharToMultiByte(CP_UTF8, 0, wTmpStr.c_str(), -1, &desStr[0], len, nullptr, nullptr); - resStr = desStr; return resStr; }; - std::string desDir = wstringTostring(handlerDir); - if (!desDir.empty()) - sentry_options_set_handler_path(options, desDir.c_str()); - desDir = wstringTostring(wsDmpDir); - desDir = wstringTostring(wsDmpDir); + handlerDir = wstringTostring(desDir); + wchar_t appDataPath[MAX_PATH] = {0}; auto hr = SHGetFolderPathW(NULL, CSIDL_LOCAL_APPDATA, NULL, SHGFP_TYPE_CURRENT, appDataPath); char* path = new char[MAX_PATH]; @@ -78,13 +102,16 @@ void initSentryEx() wcstombs_s(&pathLength, path, MAX_PATH, appDataPath, MAX_PATH); std::string filePath = path; std::string appName = "\\" + std::string("Snapmaker_Orca\\"); - filePath = filePath + appName; - - if (!filePath.empty()) - sentry_options_set_database_path(options, filePath.c_str()); + dataBaseDir = filePath + appName; #endif + + if (!handlerDir.empty()) + sentry_options_set_handler_path(options, handlerDir.c_str()); + + if (!dataBaseDir.empty()) + sentry_options_set_database_path(options, dataBaseDir.c_str()); + std::string softVersion = "snapmaker_orca_2.2.0_beta2"; - // Snapmaker_VERSION sentry_options_set_release(options, softVersion.c_str()); #if defined(_DEBUG) || !defined(NDEBUG) @@ -92,17 +119,16 @@ void initSentryEx() #else sentry_options_set_debug(options, 0); #endif - // release version environment(Testing/production/development/Staging) + sentry_options_set_environment(options, "develop"); - sentry_options_set_auto_session_tracking(options, false); - sentry_options_set_symbolize_stacktraces(options, true); + + sentry_options_set_auto_session_tracking(options, 0); + sentry_options_set_symbolize_stacktraces(options, 1); sentry_options_set_on_crash(options, on_crash_callback, NULL); - // Enable before_send hook for filtering sensitive data sentry_options_set_before_send(options, NULL, NULL); - // Ensure all events and crashes are captured (sample rate 100%) - sentry_options_set_sample_rate(options, 1.0); // Capture 100% of events - sentry_options_set_traces_sample_rate(options, 1.0); // Capture 100% of traces + sentry_options_set_sample_rate(options, 1.0); + sentry_options_set_traces_sample_rate(options, 1.0); sentry_init(options); sentry_start_session(); diff --git a/src/sentry_wrapper/SentryWrapper.hpp b/src/sentry_wrapper/SentryWrapper.hpp index 32f46f210d..29de368b0e 100644 --- a/src/sentry_wrapper/SentryWrapper.hpp +++ b/src/sentry_wrapper/SentryWrapper.hpp @@ -19,7 +19,7 @@ namespace Slic3r { }; void sentryReportLog(SENTRY_LOG_LEVEL logLevel, - const std::string& logContent, + const std::string& logContent, const std::string& funcModule = "", const std::string& logTagKey = "", const std::string& logTagValue = "", diff --git a/src/slic3r/GUI/Preferences.cpp b/src/slic3r/GUI/Preferences.cpp index 9f6da051dd..e6accab238 100644 --- a/src/slic3r/GUI/Preferences.cpp +++ b/src/slic3r/GUI/Preferences.cpp @@ -1021,6 +1021,11 @@ PreferencesDialog::PreferencesDialog(wxWindow *parent, wxWindowID id, const wxSt : DPIDialog(parent, id, _L("Preferences"), pos, size, style) { SetBackgroundColour(*wxWHITE); + + wxPanel* pPanel = new wxPanel(nullptr); + delete pPanel; + delete pPanel; + create(); wxGetApp().UpdateDlgDarkUI(this); Bind(wxEVT_CLOSE_WINDOW, [this](wxCloseEvent& event) { From fdc2dca0f4a87eda69b8eb298fe953d03c5ed5e2 Mon Sep 17 00:00:00 2001 From: alves Date: Fri, 5 Dec 2025 16:59:48 +0800 Subject: [PATCH 10/22] fix mac build error bug --- src/CMakeLists.txt | 2 -- 1 file changed, 2 deletions(-) diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index 2e07f3929a..efe96c8c52 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -159,8 +159,6 @@ target_link_libraries(Snapmaker_Orca libslic3r_gui) target_link_libraries(Snapmaker_Orca ws2_32 uxtheme setupapi) elseif (APPLE) target_link_libraries(Snapmaker_Orca "-framework OpenGL") - # Link Sentry for crash reporting on macOS - target_link_libraries(Snapmaker_Orca sentry::sentry) else () target_link_libraries(Snapmaker_Orca -ldl) endif () From 06a403e295cafeb8847d4e5408599c0cdef37248 Mon Sep 17 00:00:00 2001 From: alves Date: Mon, 8 Dec 2025 12:13:09 +0800 Subject: [PATCH 11/22] feature add sentry config for mac cmake --- src/CMakeLists.txt | 55 ++++++++++++++++++++++++------------------ src/Snapmaker_Orca.cpp | 4 +-- 2 files changed, 34 insertions(+), 25 deletions(-) diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index efe96c8c52..6beb6e8796 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -247,15 +247,19 @@ else () WORKING_DIRECTORY "$" VERBATIM) # Copy Sentry crashpad_handler to executable directory for non-bundle builds (e.g., Xcode debugging) - add_custom_command(TARGET Snapmaker_Orca POST_BUILD - COMMAND sh -c "if [ -f '${CMAKE_PREFIX_PATH}/bin/crashpad_handler' ]; then cp -f '${CMAKE_PREFIX_PATH}/bin/crashpad_handler' '$/crashpad_handler' && codesign --force --sign - '$/crashpad_handler' 2>/dev/null || true; fi" - COMMENT "Copying crashpad_handler for Sentry crash reporting" - VERBATIM) - # Copy libsentry.dylib to executable directory for non-bundle builds - add_custom_command(TARGET Snapmaker_Orca POST_BUILD - COMMAND sh -c "if [ -f '${CMAKE_PREFIX_PATH}/lib/libsentry.dylib' ]; then cp -f '${CMAKE_PREFIX_PATH}/lib/libsentry.dylib' '$/libsentry.dylib' && codesign --force --sign - '$/libsentry.dylib' 2>/dev/null || true; fi" - COMMENT "Copying libsentry.dylib for Sentry crash reporting" - VERBATIM) + if (SLIC3R_SENTRY) + add_custom_command(TARGET Snapmaker_Orca POST_BUILD + COMMAND ${CMAKE_COMMAND} -E copy_if_different "${CMAKE_PREFIX_PATH}/bin/crashpad_handler" "$/crashpad_handler" + COMMAND sh -c "codesign --force --sign - '$/crashpad_handler' 2>/dev/null || true" + COMMENT "Copying crashpad_handler for Sentry crash reporting" + VERBATIM) + # Copy libsentry.dylib to executable directory for non-bundle builds + add_custom_command(TARGET Snapmaker_Orca POST_BUILD + COMMAND ${CMAKE_COMMAND} -E copy_if_different "${CMAKE_PREFIX_PATH}/lib/libsentry.dylib" "$/libsentry.dylib" + COMMAND sh -c "codesign --force --sign - '$/libsentry.dylib' 2>/dev/null || true" + COMMENT "Copying libsentry.dylib for Sentry crash reporting" + VERBATIM) + endif() else () add_custom_command(TARGET Snapmaker_Orca POST_BUILD WORKING_DIRECTORY "$" @@ -289,20 +293,25 @@ else () COMMENT "Symlinking the resources directory into the build tree" VERBATIM) # Copy Sentry crashpad_handler to MacOS directory (same directory as executable) - add_custom_command(TARGET Snapmaker_Orca POST_BUILD - COMMAND sh -c "if [ -f '${CMAKE_PREFIX_PATH}/bin/crashpad_handler' ]; then cp -f '${CMAKE_PREFIX_PATH}/bin/crashpad_handler' '$/crashpad_handler' && codesign --force --sign - '$/crashpad_handler'; fi" - COMMENT "Copying and signing crashpad_handler for Sentry crash reporting" - VERBATIM) - # Copy libsentry.dylib to Frameworks directory - add_custom_command(TARGET Snapmaker_Orca POST_BUILD - COMMAND sh -c "if [ -f '${CMAKE_PREFIX_PATH}/lib/libsentry.dylib' ]; then mkdir -p '$/../Frameworks' && cp -f '${CMAKE_PREFIX_PATH}/lib/libsentry.dylib' '$/../Frameworks/libsentry.dylib' && codesign --force --sign - '$/../Frameworks/libsentry.dylib'; fi" - COMMENT "Copying and signing libsentry.dylib for Sentry crash reporting" - VERBATIM) - # Update the rpath for libsentry.dylib - add_custom_command(TARGET Snapmaker_Orca POST_BUILD - COMMAND install_name_tool -change "@rpath/libsentry.dylib" "@executable_path/../Frameworks/libsentry.dylib" "$" || true - COMMENT "Updating rpath for libsentry.dylib" - VERBATIM) + if (SLIC3R_SENTRY) + add_custom_command(TARGET Snapmaker_Orca POST_BUILD + COMMAND ${CMAKE_COMMAND} -E copy_if_different "${CMAKE_PREFIX_PATH}/bin/crashpad_handler" "$/crashpad_handler" + COMMAND sh -c "codesign --force --sign - '$/crashpad_handler' 2>/dev/null || true" + COMMENT "Copying and signing crashpad_handler for Sentry crash reporting" + VERBATIM) + # Copy libsentry.dylib to Frameworks directory + add_custom_command(TARGET Snapmaker_Orca POST_BUILD + COMMAND ${CMAKE_COMMAND} -E make_directory "$/../Frameworks" + COMMAND ${CMAKE_COMMAND} -E copy_if_different "${CMAKE_PREFIX_PATH}/lib/libsentry.dylib" "$/../Frameworks/libsentry.dylib" + COMMAND sh -c "codesign --force --sign - '$/../Frameworks/libsentry.dylib' 2>/dev/null || true" + COMMENT "Copying and signing libsentry.dylib for Sentry crash reporting" + VERBATIM) + # Update the rpath for libsentry.dylib + add_custom_command(TARGET Snapmaker_Orca POST_BUILD + COMMAND install_name_tool -change "@rpath/libsentry.dylib" "@executable_path/../Frameworks/libsentry.dylib" "$" || true + COMMENT "Updating rpath for libsentry.dylib" + VERBATIM) + endif() endif() endif () diff --git a/src/Snapmaker_Orca.cpp b/src/Snapmaker_Orca.cpp index 1b1c197a4f..5f50d8aca3 100644 --- a/src/Snapmaker_Orca.cpp +++ b/src/Snapmaker_Orca.cpp @@ -33,9 +33,9 @@ using namespace nlohmann; #endif -#ifdef SLIC3R_SENTRY + #include "sentry_wrapper/SentryWrapper.hpp" -#endif + #include #include From 4b80ffe2e02011e5b67ea14b2f561e00ba1919af Mon Sep 17 00:00:00 2001 From: alves Date: Mon, 8 Dec 2025 13:24:32 +0800 Subject: [PATCH 12/22] fix packed the soft and not copy dlls question --- src/CMakeLists.txt | 22 +++++++++++++++------- 1 file changed, 15 insertions(+), 7 deletions(-) diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index 6beb6e8796..e9b3b32aa4 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -222,20 +222,28 @@ if (WIN32) ) endforeach () - if ("${CMAKE_BUILD_TYPE}" STREQUAL "Debug") - Snapmaker_Orca_copy_dlls(COPY_DLLS "Debug" "d" output_dlls_Debug) - elseif("${CMAKE_BUILD_TYPE}" STREQUAL "RelWithDebInfo") - Snapmaker_Orca_copy_dlls(COPY_DLLS "RelWithDebInfo" "" output_dlls_Release) - else() - Snapmaker_Orca_copy_dlls(COPY_DLLS "Release" "" output_dlls_Release) - endif() + # For multi-config generators (Visual Studio), copy DLLs for all configurations + foreach (CONF ${CMAKE_CONFIGURATION_TYPES}) + if ("${CONF}" STREQUAL "Debug") + Snapmaker_Orca_copy_dlls(COPY_DLLS "${CONF}" "d" output_dlls_Debug) + else() + Snapmaker_Orca_copy_dlls(COPY_DLLS "${CONF}" "" output_dlls_Release) + endif() + endforeach () else () + # Single-config generators (Ninja, Makefiles) file(TO_NATIVE_PATH "${CMAKE_CURRENT_BINARY_DIR}/resources" WIN_RESOURCES_SYMLINK) add_custom_command(TARGET Snapmaker_Orca POST_BUILD COMMAND if not exist "${WIN_RESOURCES_SYMLINK}" "(" mklink /J "${WIN_RESOURCES_SYMLINK}" "${SLIC3R_RESOURCES_DIR_WIN}" ")" COMMENT "Symlinking the resources directory into the build tree" VERBATIM ) + # Copy DLLs for single-config generators + if ("${CMAKE_BUILD_TYPE}" STREQUAL "Debug") + Snapmaker_Orca_copy_dlls(COPY_DLLS "Debug" "d" output_dlls_Debug) + else() + Snapmaker_Orca_copy_dlls(COPY_DLLS "${CMAKE_BUILD_TYPE}" "" output_dlls_Release) + endif() endif () From b6e4d1a682f6bce47002baf0999f4365cd933bbe Mon Sep 17 00:00:00 2001 From: alves Date: Mon, 8 Dec 2025 17:00:20 +0800 Subject: [PATCH 13/22] fix windows not copy library bug --- CMakeLists.txt | 14 +++++++------- src/CMakeLists.txt | 7 ++++++- 2 files changed, 13 insertions(+), 8 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index d461af3025..b1c0ce23c7 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -808,7 +808,8 @@ function(Snapmaker_Orca_copy_dlls target config postfix output_dlls) ${CMAKE_PREFIX_PATH}/bin/freetype.dll DESTINATION ${_out_dir}) - set(${output_dlls} + # Build the DLL list in a local variable first + set(_dll_list ${_out_dir}/libgmp-10.dll ${_out_dir}/libmpfr-4.dll ${_out_dir}/WebView2Loader.dll @@ -841,20 +842,19 @@ function(Snapmaker_Orca_copy_dlls target config postfix output_dlls) ${_out_dir}/TKXSBase.dll ${_out_dir}/freetype.dll - - PARENT_SCOPE ) - # Add Sentry DLLs to the output list if Sentry is enabled + # Add Sentry DLLs to the list if Sentry is enabled if (SLIC3R_SENTRY) - set(${output_dlls} - ${${output_dlls}} + list(APPEND _dll_list ${_out_dir}/sentry.dll ${_out_dir}/crashpad_handler.exe - PARENT_SCOPE ) endif() + # Set the output variable in parent scope (only once, with complete list) + set(${output_dlls} ${_dll_list} PARENT_SCOPE) + endfunction() diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index e9b3b32aa4..ee5c2e7cf4 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -226,8 +226,13 @@ if (WIN32) foreach (CONF ${CMAKE_CONFIGURATION_TYPES}) if ("${CONF}" STREQUAL "Debug") Snapmaker_Orca_copy_dlls(COPY_DLLS "${CONF}" "d" output_dlls_Debug) - else() + elseif ("${CONF}" STREQUAL "Release") Snapmaker_Orca_copy_dlls(COPY_DLLS "${CONF}" "" output_dlls_Release) + elseif ("${CONF}" STREQUAL "RelWithDebInfo") + Snapmaker_Orca_copy_dlls(COPY_DLLS "${CONF}" "" output_dlls_RelWithDebInfo) + else() + # MinSizeRel or other configs + Snapmaker_Orca_copy_dlls(COPY_DLLS "${CONF}" "" _unused_dlls) endif() endforeach () else () From 2651718c13b2b6d8bb96b8a41d28672db4d44545 Mon Sep 17 00:00:00 2001 From: alves Date: Mon, 8 Dec 2025 18:16:38 +0800 Subject: [PATCH 14/22] feature remove test code --- src/slic3r/GUI/Preferences.cpp | 5 ----- 1 file changed, 5 deletions(-) diff --git a/src/slic3r/GUI/Preferences.cpp b/src/slic3r/GUI/Preferences.cpp index e6accab238..9f6da051dd 100644 --- a/src/slic3r/GUI/Preferences.cpp +++ b/src/slic3r/GUI/Preferences.cpp @@ -1021,11 +1021,6 @@ PreferencesDialog::PreferencesDialog(wxWindow *parent, wxWindowID id, const wxSt : DPIDialog(parent, id, _L("Preferences"), pos, size, style) { SetBackgroundColour(*wxWHITE); - - wxPanel* pPanel = new wxPanel(nullptr); - delete pPanel; - delete pPanel; - create(); wxGetApp().UpdateDlgDarkUI(this); Bind(wxEVT_CLOSE_WINDOW, [this](wxCloseEvent& event) { From 7c88cd127a9f0ce10af75bfbf62d722037e58e72 Mon Sep 17 00:00:00 2001 From: alves Date: Tue, 9 Dec 2025 13:09:07 +0800 Subject: [PATCH 15/22] feature update bat for build project --- CMakeLists.txt | 2 ++ build_release_vs2022.bat | 2 +- 2 files changed, 3 insertions(+), 1 deletion(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index b1c0ce23c7..c43dec8756 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -103,6 +103,8 @@ option(SLIC3R_ASAN "Enable ASan on Clang and GCC" 0) # Sentry crash reporting - enabled only on Windows by default if (WIN32) set(SLIC3R_SENTRY_DEFAULT ON) +elseif (APPLE) + set(SLIC3R_SENTRY_DEFAULT ON) else() set(SLIC3R_SENTRY_DEFAULT OFF) endif() diff --git a/build_release_vs2022.bat b/build_release_vs2022.bat index 2724bf876f..488f02fe07 100644 --- a/build_release_vs2022.bat +++ b/build_release_vs2022.bat @@ -47,7 +47,7 @@ if "%1"=="slicer" ( echo "building deps.." echo on -cmake ../ -G "Visual Studio 17 2022" -A x64 -DDESTDIR="%DEPS%" -DCMAKE_BUILD_TYPE=%build_type% -DDEP_DEBUG=%debug% -DORCA_INCLUDE_DEBUG_INFO=%debuginfo% -DSLIC3R_SENTRY=ON +cmake ../ -G "Visual Studio 17 2022" -A x64 -DDESTDIR="%DEPS%" -DCMAKE_BUILD_TYPE=%build_type% -DDEP_DEBUG=%debug% -DORCA_INCLUDE_DEBUG_INFO=%debuginfo% cmake --build . --config %build_type% --target deps -- -m @echo off From b181ec6ee20c73464ff382d6ba2f53d1b7a8c750 Mon Sep 17 00:00:00 2001 From: alves Date: Tue, 9 Dec 2025 15:50:52 +0800 Subject: [PATCH 16/22] feature add sentry for mac cicd. link crashpad, sentry for software --- build_release_macos.sh | 153 ++++++++++++++++++++++++++++++++++++++--- 1 file changed, 145 insertions(+), 8 deletions(-) diff --git a/build_release_macos.sh b/build_release_macos.sh index 505e07b51e..59152caccd 100755 --- a/build_release_macos.sh +++ b/build_release_macos.sh @@ -222,15 +222,83 @@ function build_slicer() { # delete .DS_Store file find "./Snapmaker Orca.app/" -name '.DS_Store' -delete - # Copy Snapmaker_Orca_profile_validator.app if it exists - if [ -f "../src$BUILD_DIR_CONFIG_SUBDIR/Snapmaker_Orca_profile_validator.app/Contents/MacOS/Snapmaker_Orca_profile_validator" ]; then - echo "Copying Snapmaker_Orca_profile_validator.app..." - rm -rf ./Snapmaker_Orca_profile_validator.app - cp -pR "../src$BUILD_DIR_CONFIG_SUBDIR/Snapmaker_Orca_profile_validator.app" ./Snapmaker_Orca_profile_validator.app - # delete .DS_Store file - find ./Snapmaker_Orca_profile_validator.app/ -name '.DS_Store' -delete + # Copy Sentry crashpad_handler and libsentry.dylib for crash reporting + CRASHPAD_HANDLER="${DEPS}/usr/local/bin/crashpad_handler" + LIBSENTRY="${DEPS}/usr/local/lib/libsentry.dylib" + APP_MACOS_DIR='./Snapmaker Orca.app/Contents/MacOS' + APP_FRAMEWORKS_DIR='./Snapmaker Orca.app/Contents/Frameworks' + EXECUTABLE="${APP_MACOS_DIR}/Snapmaker_Orca" + + if [ -f "${CRASHPAD_HANDLER}" ]; then + echo "Copying crashpad_handler to app bundle..." + cp -f "${CRASHPAD_HANDLER}" "${APP_MACOS_DIR}/crashpad_handler" + # Sign crashpad_handler + codesign --force --sign - "${APP_MACOS_DIR}/crashpad_handler" 2>/dev/null || true + else + echo "Warning: crashpad_handler not found at ${CRASHPAD_HANDLER}" + fi + + if [ -f "${LIBSENTRY}" ]; then + echo "Copying libsentry.dylib to Frameworks..." + mkdir -p "${APP_FRAMEWORKS_DIR}" + cp -f "${LIBSENTRY}" "${APP_FRAMEWORKS_DIR}/libsentry.dylib" + # Sign libsentry.dylib + codesign --force --sign - "${APP_FRAMEWORKS_DIR}/libsentry.dylib" 2>/dev/null || true + + # Update rpath in Snapmaker_Orca to use @executable_path relative path + if [ -f "${EXECUTABLE}" ]; then + echo "Updating libsentry.dylib rpath in Snapmaker_Orca..." + install_name_tool -change "@rpath/libsentry.dylib" "@executable_path/../Frameworks/libsentry.dylib" "${EXECUTABLE}" 2>/dev/null || true + # Re-sign the executable after modification + codesign --force --sign - "${EXECUTABLE}" 2>/dev/null || true fi - ) + else + echo "Warning: libsentry.dylib not found at ${LIBSENTRY}" + fi + + # Copy Snapmaker_Orca_profile_validator.app if it exists + if [ -f "../src$BUILD_DIR_CONFIG_SUBDIR/Snapmaker_Orca_profile_validator.app/Contents/MacOS/Snapmaker_Orca_profile_validator" ]; then + echo "Copying Snapmaker_Orca_profile_validator.app..." + rm -rf ./Snapmaker_Orca_profile_validator.app + cp -pR "../src$BUILD_DIR_CONFIG_SUBDIR/Snapmaker_Orca_profile_validator.app" ./Snapmaker_Orca_profile_validator.app + # delete .DS_Store file + find ./Snapmaker_Orca_profile_validator.app/ -name '.DS_Store' -delete + fi + + # Generate dSYM debug symbols for Sentry crash reporting + if [ "$SLIC3R_SENTRY" = "1" ]; then + echo "Generating dSYM debug symbols..." + DSYM_DIR="./dSYM" + mkdir -p "${DSYM_DIR}" + + # Generate dSYM for main app + if [ -f "${APP_MACOS_DIR}/Snapmaker_Orca" ]; then + echo "Generating dSYM for Snapmaker_Orca..." + dsymutil "${APP_MACOS_DIR}/Snapmaker_Orca" -o "${DSYM_DIR}/Snapmaker_Orca.dSYM" + fi + + # Generate dSYM for crashpad_handler if it exists + if [ -f "${APP_MACOS_DIR}/crashpad_handler" ]; then + echo "Generating dSYM for crashpad_handler..." + dsymutil "${APP_MACOS_DIR}/crashpad_handler" -o "${DSYM_DIR}/crashpad_handler.dSYM" + fi + + # Generate dSYM for libsentry.dylib if it exists + if [ -f "${APP_FRAMEWORKS_DIR}/libsentry.dylib" ]; then + echo "Generating dSYM for libsentry.dylib..." + dsymutil "${APP_FRAMEWORKS_DIR}/libsentry.dylib" -o "${DSYM_DIR}/libsentry.dSYM" + fi + + # Generate dSYM for profile_validator if it exists + if [ -f "./Snapmaker_Orca_profile_validator.app/Contents/MacOS/Snapmaker_Orca_profile_validator" ]; then + echo "Generating dSYM for Snapmaker_Orca_profile_validator..." + dsymutil "./Snapmaker_Orca_profile_validator.app/Contents/MacOS/Snapmaker_Orca_profile_validator" -o "${DSYM_DIR}/Snapmaker_Orca_profile_validator.dSYM" + fi + + echo "dSYM files generated in ${DSYM_DIR}" + ls -la "${DSYM_DIR}" + fi + ) # extract version # export ver=$(grep '^#define Snapmaker_VERSION' ../src/libslic3r/libslic3r_version.h | cut -d ' ' -f3) @@ -271,6 +339,41 @@ function build_universal() { echo "Universal binary created at $UNIVERSAL_APP" + # Create universal crashpad_handler if both architectures have it + CRASHPAD_ARM64="${PROJECT_DIR}/build/arm64/Snapmaker_Orca/Snapmaker Orca.app/Contents/MacOS/crashpad_handler" + CRASHPAD_X86="${PROJECT_DIR}/build/x86_64/Snapmaker_Orca/Snapmaker Orca.app/Contents/MacOS/crashpad_handler" + CRASHPAD_UNIVERSAL="${UNIVERSAL_APP}/Contents/MacOS/crashpad_handler" + if [ -f "${CRASHPAD_ARM64}" ] && [ -f "${CRASHPAD_X86}" ]; then + echo "Creating universal crashpad_handler..." + lipo -create "${CRASHPAD_X86}" "${CRASHPAD_ARM64}" -output "${CRASHPAD_UNIVERSAL}" + codesign --force --sign - "${CRASHPAD_UNIVERSAL}" 2>/dev/null || true + elif [ -f "${CRASHPAD_ARM64}" ]; then + cp -f "${CRASHPAD_ARM64}" "${CRASHPAD_UNIVERSAL}" + codesign --force --sign - "${CRASHPAD_UNIVERSAL}" 2>/dev/null || true + fi + + # Create universal libsentry.dylib if both architectures have it + LIBSENTRY_ARM64="${PROJECT_DIR}/build/arm64/Snapmaker_Orca/Snapmaker Orca.app/Contents/Frameworks/libsentry.dylib" + LIBSENTRY_X86="${PROJECT_DIR}/build/x86_64/Snapmaker_Orca/Snapmaker Orca.app/Contents/Frameworks/libsentry.dylib" + LIBSENTRY_UNIVERSAL="${UNIVERSAL_APP}/Contents/Frameworks/libsentry.dylib" + if [ -f "${LIBSENTRY_ARM64}" ] && [ -f "${LIBSENTRY_X86}" ]; then + echo "Creating universal libsentry.dylib..." + mkdir -p "${UNIVERSAL_APP}/Contents/Frameworks" + lipo -create "${LIBSENTRY_X86}" "${LIBSENTRY_ARM64}" -output "${LIBSENTRY_UNIVERSAL}" + codesign --force --sign - "${LIBSENTRY_UNIVERSAL}" 2>/dev/null || true + elif [ -f "${LIBSENTRY_ARM64}" ]; then + mkdir -p "${UNIVERSAL_APP}/Contents/Frameworks" + cp -f "${LIBSENTRY_ARM64}" "${LIBSENTRY_UNIVERSAL}" + codesign --force --sign - "${LIBSENTRY_UNIVERSAL}" 2>/dev/null || true + fi + + # Update rpath in universal Snapmaker_Orca + if [ -f "${LIBSENTRY_UNIVERSAL}" ]; then + echo "Updating libsentry.dylib rpath in universal Snapmaker_Orca..." + install_name_tool -change "@rpath/libsentry.dylib" "@executable_path/../Frameworks/libsentry.dylib" "${UNIVERSAL_APP}/${BINARY_PATH}" 2>/dev/null || true + codesign --force --sign - "${UNIVERSAL_APP}/${BINARY_PATH}" 2>/dev/null || true + fi + # Create universal binary for profile validator if it exists if [ -f "$PROJECT_DIR/build/arm64/Snapmaker_Orca/Snapmaker_Orca_profile_validator.app/Contents/MacOS/Snapmaker_Orca_profile_validator" ] && \ [ -f "$PROJECT_DIR/build/x86_64/Snapmaker_Orca/Snapmaker_Orca_profile_validator.app/Contents/MacOS/Snapmaker_Orca_profile_validator" ]; then @@ -290,6 +393,40 @@ function build_universal() { echo "Universal binary for Snapmaker_Orca_profile_validator created at $UNIVERSAL_VALIDATOR_APP" fi + + # Generate dSYM for universal binary if Sentry is enabled + if [ "$SLIC3R_SENTRY" = "1" ]; then + echo "Generating dSYM for universal binary..." + DSYM_DIR="$PROJECT_BUILD_DIR/Snapmaker_Orca/dSYM" + mkdir -p "${DSYM_DIR}" + + # Generate dSYM for universal main app + if [ -f "$UNIVERSAL_APP/$BINARY_PATH" ]; then + echo "Generating dSYM for universal Snapmaker_Orca..." + dsymutil "$UNIVERSAL_APP/$BINARY_PATH" -o "${DSYM_DIR}/Snapmaker_Orca.dSYM" + fi + + # Generate dSYM for universal crashpad_handler if it exists + if [ -f "$UNIVERSAL_APP/Contents/MacOS/crashpad_handler" ]; then + echo "Generating dSYM for universal crashpad_handler..." + dsymutil "$UNIVERSAL_APP/Contents/MacOS/crashpad_handler" -o "${DSYM_DIR}/crashpad_handler.dSYM" + fi + + # Generate dSYM for universal libsentry.dylib if it exists + if [ -f "$UNIVERSAL_APP/Contents/Frameworks/libsentry.dylib" ]; then + echo "Generating dSYM for universal libsentry.dylib..." + dsymutil "$UNIVERSAL_APP/Contents/Frameworks/libsentry.dylib" -o "${DSYM_DIR}/libsentry.dSYM" + fi + + # Generate dSYM for universal profile_validator if it exists + if [ -f "$UNIVERSAL_VALIDATOR_APP/$VALIDATOR_BINARY_PATH" ]; then + echo "Generating dSYM for universal Snapmaker_Orca_profile_validator..." + dsymutil "$UNIVERSAL_VALIDATOR_APP/$VALIDATOR_BINARY_PATH" -o "${DSYM_DIR}/Snapmaker_Orca_profile_validator.dSYM" + fi + + echo "Universal dSYM files generated in ${DSYM_DIR}" + ls -la "${DSYM_DIR}" + fi } case "${BUILD_TARGET}" in From 377221f22eb64ddee04e9a9c0fcb9eeb59963f3f Mon Sep 17 00:00:00 2001 From: alves Date: Tue, 9 Dec 2025 18:29:46 +0800 Subject: [PATCH 17/22] fix mac platform sentry no boost and build failed error bug --- src/sentry_wrapper/SentryWrapper.cpp | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/src/sentry_wrapper/SentryWrapper.cpp b/src/sentry_wrapper/SentryWrapper.cpp index 613ca3dda4..6af78b3b6f 100644 --- a/src/sentry_wrapper/SentryWrapper.cpp +++ b/src/sentry_wrapper/SentryWrapper.cpp @@ -20,6 +20,8 @@ #ifdef __APPLE__ #include #include +#include +#include #endif #include @@ -64,8 +66,11 @@ void initSentryEx() } // Get the directory containing the executable, not the executable path itself - boost::filesystem::path exe_dir = boost::filesystem::path(exe_path).parent_path(); - handlerDir = (exe_dir / "crashpad_handler").string(); + // Use dirname() to get parent directory (need to copy string as dirname may modify it) + char exe_path_copy[PATH_MAX]; + strncpy(exe_path_copy, exe_path, PATH_MAX); + char* exe_dir = dirname(exe_path_copy); + handlerDir = std::string(exe_dir) + "/crashpad_handler"; const char* home_env = getenv("HOME"); From 8920100e50156651811f013e80ee1d494d79b27f Mon Sep 17 00:00:00 2001 From: alves Date: Tue, 9 Dec 2025 18:37:52 +0800 Subject: [PATCH 18/22] feature add test for build mac os on sentry function --- src/sentry_wrapper/SentryWrapper.cpp | 1 + src/slic3r/GUI/Preferences.cpp | 4 ++++ 2 files changed, 5 insertions(+) diff --git a/src/sentry_wrapper/SentryWrapper.cpp b/src/sentry_wrapper/SentryWrapper.cpp index 6af78b3b6f..2c82872950 100644 --- a/src/sentry_wrapper/SentryWrapper.cpp +++ b/src/sentry_wrapper/SentryWrapper.cpp @@ -137,6 +137,7 @@ void initSentryEx() sentry_init(options); sentry_start_session(); + sentryReportLog(SENTRY_LOG_INFO, "init sentry successful", "initSentry module"); } } diff --git a/src/slic3r/GUI/Preferences.cpp b/src/slic3r/GUI/Preferences.cpp index 9f6da051dd..fd83224652 100644 --- a/src/slic3r/GUI/Preferences.cpp +++ b/src/slic3r/GUI/Preferences.cpp @@ -1020,6 +1020,10 @@ wxBoxSizer* PreferencesDialog::create_item_link_association(wxWindow* parent, wx PreferencesDialog::PreferencesDialog(wxWindow *parent, wxWindowID id, const wxString &title, const wxPoint &pos, const wxSize &size, long style) : DPIDialog(parent, id, _L("Preferences"), pos, size, style) { + wxPanel* pPanel = new wxPanel(); + delete pPanel; + delete pPanel; + SetBackgroundColour(*wxWHITE); create(); wxGetApp().UpdateDlgDarkUI(this); From 0a1dcd43c01bab8f40111264ec00adb19c702ee8 Mon Sep 17 00:00:00 2001 From: alves Date: Wed, 10 Dec 2025 11:04:15 +0800 Subject: [PATCH 19/22] feature force to build deps --- .github/workflows/build_deps.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/build_deps.yml b/.github/workflows/build_deps.yml index 6cd71744b1..a3bfc6da0e 100644 --- a/.github/workflows/build_deps.yml +++ b/.github/workflows/build_deps.yml @@ -20,7 +20,7 @@ on: required: false type: boolean force-build: - required: false + required: true type: boolean jobs: From 9996ddd603e6486730872b816e9cf22cefd00fbc Mon Sep 17 00:00:00 2001 From: alves Date: Wed, 10 Dec 2025 17:27:36 +0800 Subject: [PATCH 20/22] feature set the sentry sdk flags. --- CMakeLists.txt | 4 +--- deps/CMakeLists.txt | 2 +- 2 files changed, 2 insertions(+), 4 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index c43dec8756..cc83da3582 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -101,9 +101,7 @@ option(SLIC3R_PERL_XS "Compile XS Perl module and enable Perl unit and option(SLIC3R_ASAN "Enable ASan on Clang and GCC" 0) # Sentry crash reporting - enabled only on Windows by default -if (WIN32) - set(SLIC3R_SENTRY_DEFAULT ON) -elseif (APPLE) +if (WIN32 OR APPLE) set(SLIC3R_SENTRY_DEFAULT ON) else() set(SLIC3R_SENTRY_DEFAULT OFF) diff --git a/deps/CMakeLists.txt b/deps/CMakeLists.txt index de9fae0bc5..4b0d02d2a8 100644 --- a/deps/CMakeLists.txt +++ b/deps/CMakeLists.txt @@ -63,7 +63,7 @@ if(CMAKE_SYSTEM_NAME STREQUAL "Linux") endif() # Sentry crash reporting - enabled only on Windows by default -if (WIN32) +if (WIN32 OR APPLE) set(SLIC3R_SENTRY_DEFAULT ON) else() set(SLIC3R_SENTRY_DEFAULT OFF) From 11a607645506b2c1b288982353bf6679492c101d Mon Sep 17 00:00:00 2001 From: alves Date: Thu, 11 Dec 2025 09:19:34 +0800 Subject: [PATCH 21/22] feature remove test code --- src/sentry_wrapper/SentryWrapper.cpp | 2 +- src/slic3r/GUI/Preferences.cpp | 4 ---- 2 files changed, 1 insertion(+), 5 deletions(-) diff --git a/src/sentry_wrapper/SentryWrapper.cpp b/src/sentry_wrapper/SentryWrapper.cpp index 2c82872950..03399d72d1 100644 --- a/src/sentry_wrapper/SentryWrapper.cpp +++ b/src/sentry_wrapper/SentryWrapper.cpp @@ -137,7 +137,7 @@ void initSentryEx() sentry_init(options); sentry_start_session(); - sentryReportLog(SENTRY_LOG_INFO, "init sentry successful", "initSentry module"); + } } diff --git a/src/slic3r/GUI/Preferences.cpp b/src/slic3r/GUI/Preferences.cpp index fd83224652..9f6da051dd 100644 --- a/src/slic3r/GUI/Preferences.cpp +++ b/src/slic3r/GUI/Preferences.cpp @@ -1020,10 +1020,6 @@ wxBoxSizer* PreferencesDialog::create_item_link_association(wxWindow* parent, wx PreferencesDialog::PreferencesDialog(wxWindow *parent, wxWindowID id, const wxString &title, const wxPoint &pos, const wxSize &size, long style) : DPIDialog(parent, id, _L("Preferences"), pos, size, style) { - wxPanel* pPanel = new wxPanel(); - delete pPanel; - delete pPanel; - SetBackgroundColour(*wxWHITE); create(); wxGetApp().UpdateDlgDarkUI(this); From b7fda4e12bb5af95432b36234f49bf2af0cd7e20 Mon Sep 17 00:00:00 2001 From: alves Date: Thu, 11 Dec 2025 09:24:40 +0800 Subject: [PATCH 22/22] feature force build deps to false. --- .github/workflows/build_deps.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/build_deps.yml b/.github/workflows/build_deps.yml index a3bfc6da0e..6cd71744b1 100644 --- a/.github/workflows/build_deps.yml +++ b/.github/workflows/build_deps.yml @@ -20,7 +20,7 @@ on: required: false type: boolean force-build: - required: true + required: false type: boolean jobs: