From 66ef7f562143380da7022a46af74c7e57a76e5da Mon Sep 17 00:00:00 2001 From: Germano Cavalcante Date: Tue, 22 Jul 2025 09:04:14 +0200 Subject: [PATCH] Fix #142314: Crash popup blocks automation in background mode Crash popups were being displayed even when Blender was running in background mode, causing the process to hang and blocking automated workflows (e.g., render farms). Therefore, disable the crash popup when running in background mode. Pull Request: https://projects.blender.org/blender/blender/pulls/142518 --- source/blender/blenlib/BLI_system.h | 12 ++++-- source/blender/blenlib/intern/system_win32.cc | 39 ++++++------------- source/creator/creator_signals.cc | 31 ++++++++------- 3 files changed, 37 insertions(+), 45 deletions(-) diff --git a/source/blender/blenlib/BLI_system.h b/source/blender/blenlib/BLI_system.h index 508f43798cb..dd9b4175ed5 100644 --- a/source/blender/blenlib/BLI_system.h +++ b/source/blender/blenlib/BLI_system.h @@ -43,12 +43,16 @@ int BLI_system_memory_max_in_megabytes_int(void); # define BLI_SYSTEM_PID_H /** - * \note Use `void *` for `exception` since we really do not want to drag Windows.h + * \note Use `void *` for `os_info` since we really do not want to drag Windows.h * in to get the proper `typedef`. */ -void BLI_windows_exception_capture(void *exception); -void BLI_windows_exception_show_dialog(const void *exception, - const char *filepath_crashlog, +void BLI_windows_exception_print_message(const void *os_info); + +/** + * Displays a crash report dialog with options to open the crash log, restart the application, and + * report a bug. This is based on the `showMessageBox` function in `GHOST_SystemWin32.cc`. + */ +void BLI_windows_exception_show_dialog(const char *filepath_crashlog, const char *filepath_relaunch, const char *gpu_name, const char *build_version); diff --git a/source/blender/blenlib/intern/system_win32.cc b/source/blender/blenlib/intern/system_win32.cc index 98ed6e1000c..afac15bac6e 100644 --- a/source/blender/blenlib/intern/system_win32.cc +++ b/source/blender/blenlib/intern/system_win32.cc @@ -425,14 +425,13 @@ void BLI_system_backtrace_with_os_info(FILE *fp, const void *os_info) bli_windows_system_backtrace_modules(fp); } -static void bli_windows_exception_message_get(const EXCEPTION_POINTERS *exception, - char r_message[512]) +void BLI_windows_exception_print_message(const void *os_info) { - if (!exception) { - r_message[0] = '\0'; + if (!os_info) { return; } + const EXCEPTION_POINTERS *exception = static_cast(os_info); const char *exception_name = bli_windows_get_exception_description( exception->ExceptionRecord->ExceptionCode); LPVOID address = exception->ExceptionRecord->ExceptionAddress; @@ -440,7 +439,8 @@ static void bli_windows_exception_message_get(const EXCEPTION_POINTERS *exceptio bli_windows_get_module_name(address, modulename, sizeof(modulename)); DWORD threadId = GetCurrentThreadId(); - BLI_snprintf(r_message, + char message[512]; + BLI_snprintf(message, 512, "Error : %s\n" "Address : 0x%p\n" @@ -450,6 +450,9 @@ static void bli_windows_exception_message_get(const EXCEPTION_POINTERS *exceptio address, modulename, threadId); + + fprintf(stderr, message); + fflush(stderr); } /* -------------------------------------------------------------------- */ @@ -571,14 +574,10 @@ static std::wstring url_encode_wstring(const std::string &str) return result; } -/** - * Displays a crash report dialog with options to open the crash log, restart the application, and - * report a bug. This is based on the `showMessageBox` function in `GHOST_SystemWin32.cc`. - */ -static void bli_show_crash_report_dialog(const char *filepath_crashlog, - const char *filepath_relaunch, - const char *gpu_name, - const char *build_version) +void BLI_windows_exception_show_dialog(const char *filepath_crashlog, + const char *filepath_relaunch, + const char *gpu_name, + const char *build_version) { /* Redundant: #InitCommonControls is already called during GHOST System initialization. */ // InitCommonControls(); @@ -683,18 +682,4 @@ static void bli_show_crash_report_dialog(const char *filepath_crashlog, free((void *)filepath_relaunch_utf16); } -void BLI_windows_exception_show_dialog(const void *exception, - const char *filepath_crashlog, - const char *filepath_relaunch, - const char *gpu_name, - const char *build_version) -{ - char message[512]; - bli_windows_exception_message_get(static_cast(exception), message); - fprintf(stderr, message); - fflush(stderr); - - bli_show_crash_report_dialog(filepath_crashlog, filepath_relaunch, gpu_name, build_version); -} - /** \} */ diff --git a/source/creator/creator_signals.cc b/source/creator/creator_signals.cc index e6619347578..fa2abd8c3e8 100644 --- a/source/creator/creator_signals.cc +++ b/source/creator/creator_signals.cc @@ -171,23 +171,26 @@ extern LONG WINAPI windows_exception_handler(EXCEPTION_POINTERS *ExceptionInfo) } } else { - std::string version; -# ifndef BUILD_DATE - const char *build_hash = G_MAIN ? G_MAIN->build_hash : "unknown"; - version = std::string(BKE_blender_version_string()) + ", hash: `" + build_hash + "`"; -# else - version = std::string(BKE_blender_version_string()) + ", Commit date: " + build_commit_date + - " " + build_commit_time + ", hash: `" + build_hash + "`"; -# endif - char filepath_crashlog[FILE_MAX]; + BLI_windows_exception_print_message(ExceptionInfo); BKE_blender_globals_crash_path_get(filepath_crashlog); crashlog_file_generate(filepath_crashlog, ExceptionInfo); - BLI_windows_exception_show_dialog(ExceptionInfo, - filepath_crashlog, - G.filepath_last_blend, - GPU_platform_gpu_name(), - version.c_str()); + + /* Disable popup in background mode to avoid blocking automation. + * (e.g., when used by a render farm; see #142314). */ + if (!G.background) { + std::string version; +# ifndef BUILD_DATE + const char *build_hash = G_MAIN ? G_MAIN->build_hash : "unknown"; + version = std::string(BKE_blender_version_string()) + ", hash: `" + build_hash + "`"; +# else + version = std::string(BKE_blender_version_string()) + ", Commit date: " + build_commit_date + + " " + build_commit_time + ", hash: `" + build_hash + "`"; +# endif + + BLI_windows_exception_show_dialog( + filepath_crashlog, G.filepath_last_blend, GPU_platform_gpu_name(), version.c_str()); + } sig_cleanup_and_terminate(SIGSEGV); }