31# pragma clang diagnostic ignored "-Wdeprecated-declarations"
38 switch (exceptioncode) {
39 case EXCEPTION_ACCESS_VIOLATION:
40 return "EXCEPTION_ACCESS_VIOLATION";
41 case EXCEPTION_ARRAY_BOUNDS_EXCEEDED:
42 return "EXCEPTION_ARRAY_BOUNDS_EXCEEDED";
43 case EXCEPTION_BREAKPOINT:
44 return "EXCEPTION_BREAKPOINT";
45 case EXCEPTION_DATATYPE_MISALIGNMENT:
46 return "EXCEPTION_DATATYPE_MISALIGNMENT";
47 case EXCEPTION_FLT_DENORMAL_OPERAND:
48 return "EXCEPTION_FLT_DENORMAL_OPERAND";
49 case EXCEPTION_FLT_DIVIDE_BY_ZERO:
50 return "EXCEPTION_FLT_DIVIDE_BY_ZERO";
51 case EXCEPTION_FLT_INEXACT_RESULT:
52 return "EXCEPTION_FLT_INEXACT_RESULT";
53 case EXCEPTION_FLT_INVALID_OPERATION:
54 return "EXCEPTION_FLT_INVALID_OPERATION";
55 case EXCEPTION_FLT_OVERFLOW:
56 return "EXCEPTION_FLT_OVERFLOW";
57 case EXCEPTION_FLT_STACK_CHECK:
58 return "EXCEPTION_FLT_STACK_CHECK";
59 case EXCEPTION_FLT_UNDERFLOW:
60 return "EXCEPTION_FLT_UNDERFLOW";
61 case EXCEPTION_ILLEGAL_INSTRUCTION:
62 return "EXCEPTION_ILLEGAL_INSTRUCTION";
63 case EXCEPTION_IN_PAGE_ERROR:
64 return "EXCEPTION_IN_PAGE_ERROR";
65 case EXCEPTION_INT_DIVIDE_BY_ZERO:
66 return "EXCEPTION_INT_DIVIDE_BY_ZERO";
67 case EXCEPTION_INT_OVERFLOW:
68 return "EXCEPTION_INT_OVERFLOW";
69 case EXCEPTION_INVALID_DISPOSITION:
70 return "EXCEPTION_INVALID_DISPOSITION";
71 case EXCEPTION_NONCONTINUABLE_EXCEPTION:
72 return "EXCEPTION_NONCONTINUABLE_EXCEPTION";
73 case EXCEPTION_PRIV_INSTRUCTION:
74 return "EXCEPTION_PRIV_INSTRUCTION";
75 case EXCEPTION_SINGLE_STEP:
76 return "EXCEPTION_SINGLE_STEP";
77 case EXCEPTION_STACK_OVERFLOW:
78 return "EXCEPTION_STACK_OVERFLOW";
83 return "Microsoft C++ Exception";
85 return "UNKNOWN EXCEPTION";
93 if (GetModuleHandleEx(
94 GET_MODULE_HANDLE_EX_FLAG_FROM_ADDRESS,
static_cast<LPCSTR
>(address), &
mod))
96 if (GetModuleFileName(
mod, buffer, size)) {
97 PathStripPath(buffer);
109 LPBYTE lpBuffer =
nullptr;
110 DWORD verSize = GetFileVersionInfoSize(file, &verHandle);
112 LPSTR verData = (LPSTR)calloc(1, verSize);
114 if (GetFileVersionInfo(file, verHandle, verSize, verData)) {
115 if (VerQueryValue(verData,
"\\", (VOID FAR * FAR *)&lpBuffer, &size)) {
117 VS_FIXEDFILEINFO *verInfo = (VS_FIXEDFILEINFO *)lpBuffer;
121 if (verInfo->dwSignature == 0xfeef04bd) {
125 (verInfo->dwFileVersionMS >> 16) & 0xffff,
126 (verInfo->dwFileVersionMS >> 0) & 0xffff,
127 (verInfo->dwFileVersionLS >> 16) & 0xffff,
128 (verInfo->dwFileVersionLS >> 0) & 0xffff);
139 char module[MAX_PATH];
140 fprintf(fp,
"Exception Record:\n\n");
142 "ExceptionCode : %s (0x%.8lx)\n",
144 record->ExceptionCode);
145 fprintf(fp,
"Exception Address : 0x%p\n", record->ExceptionAddress);
147 fprintf(fp,
"Exception Module : %s\n", module);
148 fprintf(fp,
"Exception Flags : 0x%.8lx\n", record->ExceptionFlags);
149 fprintf(fp,
"Exception Parameters : 0x%lx\n", record->NumberParameters);
152 if (record->ExceptionCode == EXCEPTION_ACCESS_VIOLATION && record->NumberParameters == 2) {
154 switch (record->ExceptionInformation[0]) {
169 "\tParameters[0] (action) : 0x%p (%s)\n",
170 (LPVOID *)record->ExceptionInformation[0],
172 fprintf(fp,
"\tParameters[1] (address) : 0x%p\n", (LPVOID *)record->ExceptionInformation[1]);
175 for (DWORD idx = 0; idx < record->NumberParameters; idx++) {
176 fprintf(fp,
"\tParameters[%lu] : 0x%p\n", idx, (LPVOID *)record->ExceptionInformation[idx]);
179 if (record->ExceptionRecord) {
180 fprintf(fp,
"Nested ");
190 const int max_symbol_length = 100;
194 PSYMBOL_INFO symbolinfo =
static_cast<PSYMBOL_INFO
>(
195 calloc(1,
sizeof(SYMBOL_INFO) + max_symbol_length *
sizeof(
char)));
196 symbolinfo->MaxNameLen = max_symbol_length - 1;
197 symbolinfo->SizeOfStruct =
sizeof(SYMBOL_INFO);
199 STACKFRAME frame = {{0}};
200 DWORD machineType = 0;
202 frame.AddrPC.Offset = context->Rip;
203 frame.AddrPC.Mode = AddrModeFlat;
204 frame.AddrFrame.Offset = context->Rsp;
205 frame.AddrFrame.Mode = AddrModeFlat;
206 frame.AddrStack.Offset = context->Rsp;
207 frame.AddrStack.Mode = AddrModeFlat;
208 machineType = IMAGE_FILE_MACHINE_AMD64;
209#elif defined(_M_ARM64)
210 frame.AddrPC.Offset = context->Pc;
211 frame.AddrPC.Mode = AddrModeFlat;
212 frame.AddrFrame.Offset = context->Fp;
213 frame.AddrFrame.Mode = AddrModeFlat;
214 frame.AddrStack.Offset = context->Sp;
215 frame.AddrStack.Mode = AddrModeFlat;
216 machineType = IMAGE_FILE_MACHINE_ARM64;
220 if (StackWalk64(machineType,
226 SymFunctionTableAccess64,
230 if (frame.AddrPC.Offset) {
231 char module[MAX_PATH];
235 if (SymFromAddr(GetCurrentProcess(), (DWORD64)(frame.AddrPC.Offset), 0, symbolinfo)) {
236 fprintf(fp,
"%-20s:0x%p %s", module, (LPVOID)symbolinfo->Address, symbolinfo->Name);
237 IMAGEHLP_LINE lineinfo;
238 lineinfo.SizeOfStruct =
sizeof(lineinfo);
239 DWORD displacement = 0;
240 if (SymGetLineFromAddr(
241 GetCurrentProcess(), (DWORD64)(frame.AddrPC.Offset), &displacement, &lineinfo))
243 fprintf(fp,
" %s:%lu", lineinfo.FileName, lineinfo.LineNumber);
251 (LPVOID)frame.AddrPC.Offset,
252 "Symbols not available");
272 CONTEXT context = {0};
273 context.ContextFlags = CONTEXT_ALL;
276 if (hThread != GetCurrentThread()) {
277 SuspendThread(hThread);
278 bool success = GetThreadContext(hThread, &context);
279 ResumeThread(hThread);
281 fprintf(fp,
"Cannot get thread context : 0x0%.8lx\n", GetLastError());
286 RtlCaptureContext(&context);
293 fprintf(fp,
"Loaded Modules :\n");
294 HANDLE hModuleSnap = CreateToolhelp32Snapshot(TH32CS_SNAPMODULE, 0);
295 if (hModuleSnap == INVALID_HANDLE_VALUE) {
300 me32.dwSize =
sizeof(MODULEENTRY32);
302 if (!Module32First(hModuleSnap, &me32)) {
303 CloseHandle(hModuleSnap);
304 fprintf(fp,
" Error getting module list.\n");
309 if (me32.th32ProcessID == GetCurrentProcessId()) {
310 char version[MAX_PATH];
313 IMAGEHLP_MODULE64 m64;
314 m64.SizeOfStruct =
sizeof(m64);
315 if (SymGetModuleInfo64(GetCurrentProcess(), (DWORD64)me32.modBaseAddr, &m64)) {
317 "0x%p %-20s %s %s %s\n",
322 m64.PdbUnmatched ?
"[unmatched]" :
"");
325 fprintf(fp,
"0x%p %-20s %s\n", me32.modBaseAddr, version, me32.szModule);
328 }
while (Module32Next(hModuleSnap, &me32));
333 fprintf(fp,
"Threads:\n");
334 HANDLE hThreadSnap = INVALID_HANDLE_VALUE;
337 hThreadSnap = CreateToolhelp32Snapshot(TH32CS_SNAPTHREAD, 0);
338 if (hThreadSnap == INVALID_HANDLE_VALUE) {
339 fprintf(fp,
"Unable to retrieve threads list.\n");
343 te32.dwSize =
sizeof(THREADENTRY32);
345 if (!Thread32First(hThreadSnap, &te32)) {
346 CloseHandle(hThreadSnap);
350 if (te32.th32OwnerProcessID == GetCurrentProcessId()) {
351 if (GetCurrentThreadId() != te32.th32ThreadID) {
352 fprintf(fp,
"Thread : %.8lx\n", te32.th32ThreadID);
353 HANDLE ht = OpenThread(THREAD_ALL_ACCESS, FALSE, te32.th32ThreadID);
358 }
while (Thread32Next(hThreadSnap, &te32));
359 CloseHandle(hThreadSnap);
364 fprintf(fp,
"Stack trace:\n");
366 if (exception_info && exception_info->ExceptionRecord->ExceptionAddress) {
369 CONTEXT TempContext = *exception_info->ContextRecord;
380 IMAGEHLP_MODULE64 m64;
381 m64.SizeOfStruct =
sizeof(m64);
382 if (SymGetModuleInfo64(GetCurrentProcess(), (DWORD64)GetModuleHandle(
nullptr), &m64)) {
383 return m64.GlobalSymbols;
395 char pdb_file[MAX_PATH] = {0};
398 if (GetModuleFileNameA(
nullptr, pdb_file,
sizeof(pdb_file))) {
400 PathRemoveFileSpecA(pdb_file);
402 PathAppendA(pdb_file,
"blender.pdb");
403 if (PathFileExistsA(pdb_file)) {
404 HMODULE
mod = GetModuleHandle(
nullptr);
406 WIN32_FILE_ATTRIBUTE_DATA file_data;
407 if (GetFileAttributesExA(pdb_file, GetFileExInfoStandard, &file_data)) {
410 SymUnloadModule64(GetCurrentProcess(), (DWORD64)
mod);
412 DWORD64 module_base = SymLoadModule(GetCurrentProcess(),
417 (DWORD)file_data.nFileSizeLow);
418 if (module_base == 0) {
420 "Error loading symbols %s\n\terror:0x%.8lx\n\tsize = %lu\n\tbase=0x%p\n",
423 file_data.nFileSizeLow,
434 const EXCEPTION_POINTERS *exception_info =
static_cast<const EXCEPTION_POINTERS *
>(os_info);
435 SymInitialize(GetCurrentProcess(),
nullptr, TRUE);
437 if (exception_info) {
454 const EXCEPTION_POINTERS *exception =
static_cast<const EXCEPTION_POINTERS *
>(os_info);
456 exception->ExceptionRecord->ExceptionCode);
457 LPVOID address = exception->ExceptionRecord->ExceptionAddress;
458 CHAR modulename[MAX_PATH];
460 DWORD threadId = GetCurrentThreadId();
474 fprintf(stderr,
"%s", message);
484 OSVERSIONINFOEX osvi;
485 ZeroMemory(&osvi,
sizeof(OSVERSIONINFOEX));
486 osvi.dwOSVersionInfoSize =
sizeof(OSVERSIONINFOEX);
487 if (!GetVersionEx((OSVERSIONINFO *)&osvi)) {
488 return "Unknown System";
491 std::string version = std::to_string(osvi.dwMajorVersion) +
"-" +
492 std::to_string(osvi.dwMajorVersion) +
"." +
493 std::to_string(osvi.dwMinorVersion) +
"." +
494 std::to_string(osvi.dwBuildNumber) +
"-SP" +
495 std::to_string(osvi.wServicePackMajor);
499 std::string architecture;
500 switch (si.wProcessorArchitecture) {
501 case PROCESSOR_ARCHITECTURE_AMD64:
502 architecture =
"64 Bits";
504 case PROCESSOR_ARCHITECTURE_INTEL:
505 architecture =
"32 Bits";
507 case PROCESSOR_ARCHITECTURE_ARM:
508 architecture =
"ARM Architecture";
510 case PROCESSOR_ARCHITECTURE_ARM64:
511 architecture =
"ARM64 Architecture";
513 case PROCESSOR_ARCHITECTURE_ARM32_ON_WIN64:
514 architecture =
"ARM32 on Windows 64-bit";
516 case PROCESSOR_ARCHITECTURE_IA32_ON_ARM64:
517 architecture =
"IA32 on ARM64";
520 architecture =
"Unknown Architecture";
523 return "Windows-" + version +
" " + architecture;
532 wchar_t executable_path[MAX_PATH];
533 DWORD nSize = GetModuleFileNameW(
nullptr, executable_path, MAX_PATH);
534 if (nSize == 0 || nSize == MAX_PATH) {
543 if (wcscpy_s(path, size, executable_path) != 0) {
548 if (!PathRemoveFileSpecW(executable_path)) {
552 if (!PathAppendW(executable_path,
L"blender-launcher.exe")) {
558 DWORD attributes = GetFileAttributesW(executable_path);
559 if (attributes == INVALID_FILE_ATTRIBUTES || (attributes & FILE_ATTRIBUTE_DIRECTORY)) {
564 if (wcslen(executable_path) + 1 > size) {
570 if (wcscpy_s(path, size, executable_path) != 0) {
581 size_t len =
str.length();
584 size_t encoded_len_max =
len * 3 + 1;
586 char *encoded_str =
new char[encoded_len_max];
590 std::wstring
result(encoded_str, encoded_str + strlen(encoded_str));
592 delete[] encoded_str;
598 const char *filepath_relaunch,
599 const char *gpu_name,
600 const char *build_version)
607 wchar_t *filepath_relaunch_utf16 = filepath_relaunch[0] ?
611 std::wstring full_message_16 =
612 L"A problem has caused the program to stop functioning correctly. If you know the steps to "
613 L"reproduce this issue, please submit a bug report.\n"
615 L"The crash log can be found at:\n" +
616 std::wstring(filepath_crashlog_utf16);
618 TASKDIALOGCONFIG config = {0};
619 const TASKDIALOG_BUTTON buttons[] = {{IDRETRY,
L"Restart"},
620 {IDOK,
L"Report a Bug"},
621 {IDHELP,
L"View Crash Log"},
622 {IDCLOSE,
L"Close"}};
624 config.cbSize =
sizeof(config);
625 config.hwndParent = GetActiveWindow();
626 config.hInstance = 0;
627 config.dwCommonButtons = 0;
628 config.pszMainIcon = TD_ERROR_ICON;
629 config.pszWindowTitle =
L"Blender";
630 config.pszMainInstruction =
L"Blender has stopped working";
631 config.pszContent = full_message_16.c_str();
632 config.pButtons = buttons;
637 const wchar_t *filepath_crashlog_utf16;
638 const wchar_t *filepath_relaunch_utf16;
639 const char *gpu_name;
640 const char *build_version;
641 }
data = {filepath_crashlog_utf16, filepath_relaunch_utf16, gpu_name, build_version};
642 config.lpCallbackData =
reinterpret_cast<LONG_PTR
>(&
data);
645 config.pfCallback = [](HWND ,
649 LONG_PTR dwRefData) -> HRESULT {
650 const Data *data_ptr =
reinterpret_cast<const Data *
>(dwRefData);
651 if (uNotification != TDN_BUTTON_CLICKED) {
654 int pnButton =
static_cast<int>(wParam);
660 wchar_t executable_path[MAX_PATH];
662 std::wstring parameters;
663 if (data_ptr->filepath_relaunch_utf16) {
665 parameters =
L"\"" + std::wstring(data_ptr->filepath_relaunch_utf16) +
L"\"";
672 nullptr,
L"open", executable_path, parameters.c_str(),
nullptr, SW_SHOWNORMAL);
679 nullptr,
L"open", data_ptr->filepath_crashlog_utf16,
nullptr,
nullptr, SW_SHOWNORMAL);
685 L"https://redirect.blender.org/"
691 L"&utm_content=crash_dialog";
693 ShellExecuteW(
nullptr,
L"open", link.c_str(),
nullptr,
nullptr, SW_SHOWNORMAL);
701 TaskDialogIndirect(&config,
nullptr,
nullptr,
nullptr);
702 free(
static_cast<void *
>(filepath_crashlog_utf16));
703 free(
static_cast<void *
>(filepath_relaunch_utf16));
Read Blender memory allocation and freeing.
VecBase< float, D > constexpr mod(VecOp< float, D >, VecOp< float, D >) RET
ccl_device_inline dual1 len(const ccl_private dual< T > &a)
void free(Subdiv *subdiv)
size_t BLI_snprintf(char *__restrict dst, size_t dst_maxncpy, const char *__restrict format,...) ATTR_NONNULL(1
static bool bli_windows_system_backtrace_stack_thread(FILE *fp, HANDLE hThread)
void BLI_windows_exception_print_message(const void *os_info)
static void bli_windows_system_backtrace_exception_record(FILE *fp, PEXCEPTION_RECORD record)
static void bli_windows_get_module_version(const char *file, char *buffer, size_t buffersize)
static void bli_windows_system_backtrace_threads(FILE *fp)
void BLI_system_backtrace_with_os_info(FILE *fp, const void *os_info)
static bool bli_executable_path_get(LPWSTR path, DWORD size)
static void bli_windows_system_backtrace_modules(FILE *fp)
BMesh const char void * data
static const char * bli_windows_get_exception_description(const DWORD exceptioncode)
void BLI_windows_exception_show_dialog(const char *filepath_crashlog, const char *filepath_relaunch, const char *gpu_name, const char *build_version)
constexpr size_t ARRAY_SIZE(const T(&arg)[N]) noexcept
static std::wstring url_encode_wstring(const std::string &str)
static bool BLI_windows_system_backtrace_run_trace(FILE *fp, HANDLE hThread, PCONTEXT context)
static bool bli_private_symbols_loaded()
static std::string get_os_info()
static bool bli_windows_system_backtrace_stack(FILE *fp, const EXCEPTION_POINTERS *exception_info)
static void bli_load_symbols()
static void bli_windows_get_module_name(LPVOID address, PCHAR buffer, size_t size)
bool url_encode(const char *str, char *dst, size_t dst_size)
Encodes a string into URL format by converting special characters into percent-encoded sequences.
wchar_t * alloc_utf16_from_8(const char *in8, size_t add)