Blender V5.3
system_win32.cc
Go to the documentation of this file.
1/* SPDX-FileCopyrightText: 2023 Blender Authors
2 *
3 * SPDX-License-Identifier: GPL-2.0-or-later */
4
8
9#include <Windows.h>
10#include <commctrl.h>
11#include <sstream>
12
13#include <dbghelp.h>
14#include <shellapi.h>
15#include <shlwapi.h>
16#include <tlhelp32.h>
17
18#include "MEM_guardedalloc.h"
19
20#include "uri_convert.hh"
21#include "utfconv.hh"
22
23#include "BLI_string.hh"
24
25#include "BLI_system.hh" /* Own include. */
26
27/* GetVersionEx is deprecated and also tends to lie about much of the information
28 * it gives you. We should deal with that one day, but today is not that day. For
29 * now suppress the warning only clang-cl appears to be emitting */
30#if defined(__clang__)
31# pragma clang diagnostic ignored "-Wdeprecated-declarations"
32#endif
33
34namespace blender {
35
36static const char *bli_windows_get_exception_description(const DWORD exceptioncode)
37{
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";
79 /* This one does not have a known define, but the MSVC runtime raises this for uncaught C++
80 * exceptions. See https://devblogs.microsoft.com/oldnewthing/20100730-00/?p=13273 for
81 * details. */
82 case 0xe06d7363:
83 return "Microsoft C++ Exception";
84 default:
85 return "UNKNOWN EXCEPTION";
86 }
87}
88
89static void bli_windows_get_module_name(LPVOID address, PCHAR buffer, size_t size)
90{
91 HMODULE mod;
92 buffer[0] = 0;
93 if (GetModuleHandleEx(
94 GET_MODULE_HANDLE_EX_FLAG_FROM_ADDRESS, static_cast<LPCSTR>(address), &mod))
95 {
96 if (GetModuleFileName(mod, buffer, size)) {
97 PathStripPath(buffer);
98 }
99 }
100}
101
102/* Note: Because this code can run after main exits the MEM_* api is not available, and the stock
103 * calloc/free *must* be used. */
104static void bli_windows_get_module_version(const char *file, char *buffer, size_t buffersize)
105{
106 buffer[0] = 0;
107 DWORD verHandle = 0;
108 UINT size = 0;
109 LPBYTE lpBuffer = nullptr;
110 DWORD verSize = GetFileVersionInfoSize(file, &verHandle);
111 if (verSize != 0) {
112 LPSTR verData = (LPSTR)calloc(1, verSize);
113
114 if (GetFileVersionInfo(file, verHandle, verSize, verData)) {
115 if (VerQueryValue(verData, "\\", (VOID FAR * FAR *)&lpBuffer, &size)) {
116 if (size) {
117 VS_FIXEDFILEINFO *verInfo = (VS_FIXEDFILEINFO *)lpBuffer;
118 /* Magic value from
119 * https://docs.microsoft.com/en-us/windows/win32/api/verrsrc/ns-verrsrc-vs_fixedfileinfo
120 */
121 if (verInfo->dwSignature == 0xfeef04bd) {
122 BLI_snprintf(buffer,
123 buffersize,
124 "%d.%d.%d.%d",
125 (verInfo->dwFileVersionMS >> 16) & 0xffff,
126 (verInfo->dwFileVersionMS >> 0) & 0xffff,
127 (verInfo->dwFileVersionLS >> 16) & 0xffff,
128 (verInfo->dwFileVersionLS >> 0) & 0xffff);
129 }
130 }
131 }
132 }
133 free(verData);
134 }
135}
136
137static void bli_windows_system_backtrace_exception_record(FILE *fp, PEXCEPTION_RECORD record)
138{
139 char module[MAX_PATH];
140 fprintf(fp, "Exception Record:\n\n");
141 fprintf(fp,
142 "ExceptionCode : %s (0x%.8lx)\n",
143 bli_windows_get_exception_description(record->ExceptionCode),
144 record->ExceptionCode);
145 fprintf(fp, "Exception Address : 0x%p\n", record->ExceptionAddress);
146 bli_windows_get_module_name(record->ExceptionAddress, module, sizeof(module));
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);
150
151 /* Special handling for access violations to make them a little easier to read. */
152 if (record->ExceptionCode == EXCEPTION_ACCESS_VIOLATION && record->NumberParameters == 2) {
153 const char *action;
154 switch (record->ExceptionInformation[0]) {
155 case 0:
156 action = "read";
157 break;
158 case 1:
159 action = "write";
160 break;
161 case 8:
162 action = "execute";
163 break;
164 default:
165 action = "unknown";
166 break;
167 }
168 fprintf(fp,
169 "\tParameters[0] (action) : 0x%p (%s)\n",
170 (LPVOID *)record->ExceptionInformation[0],
171 action);
172 fprintf(fp, "\tParameters[1] (address) : 0x%p\n", (LPVOID *)record->ExceptionInformation[1]);
173 }
174 else {
175 for (DWORD idx = 0; idx < record->NumberParameters; idx++) {
176 fprintf(fp, "\tParameters[%lu] : 0x%p\n", idx, (LPVOID *)record->ExceptionInformation[idx]);
177 }
178 }
179 if (record->ExceptionRecord) {
180 fprintf(fp, "Nested ");
181 bli_windows_system_backtrace_exception_record(fp, record->ExceptionRecord);
182 }
183 fprintf(fp, "\n\n");
184}
185
186/* Note: Because this code can run after main exits the MEM_* api is not available, and the stock
187 * calloc/free *must* be used. */
188static bool BLI_windows_system_backtrace_run_trace(FILE *fp, HANDLE hThread, PCONTEXT context)
189{
190 const int max_symbol_length = 100;
191
192 bool result = true;
193
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);
198
199 STACKFRAME frame = {{0}};
200 DWORD machineType = 0;
201#if defined(_M_AMD64)
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;
217#endif
218
219 while (true) {
220 if (StackWalk64(machineType,
221 GetCurrentProcess(),
222 hThread,
223 &frame,
224 context,
225 nullptr,
226 SymFunctionTableAccess64,
227 SymGetModuleBase64,
228 0))
229 {
230 if (frame.AddrPC.Offset) {
231 char module[MAX_PATH];
232
233 bli_windows_get_module_name((LPVOID)frame.AddrPC.Offset, module, sizeof(module));
234
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))
242 {
243 fprintf(fp, " %s:%lu", lineinfo.FileName, lineinfo.LineNumber);
244 }
245 fprintf(fp, "\n");
246 }
247 else {
248 fprintf(fp,
249 "%-20s:0x%p %s\n",
250 module,
251 (LPVOID)frame.AddrPC.Offset,
252 "Symbols not available");
253 result = false;
254 break;
255 }
256 }
257 else {
258 break;
259 }
260 }
261 else {
262 break;
263 }
264 }
265 free(symbolinfo);
266 fprintf(fp, "\n\n");
267 return result;
268}
269
270static bool bli_windows_system_backtrace_stack_thread(FILE *fp, HANDLE hThread)
271{
272 CONTEXT context = {0};
273 context.ContextFlags = CONTEXT_ALL;
274 /* GetThreadContext requires the thread to be in a suspended state, which is problematic for the
275 * currently running thread, RtlCaptureContext is used as an alternative to sidestep this */
276 if (hThread != GetCurrentThread()) {
277 SuspendThread(hThread);
278 bool success = GetThreadContext(hThread, &context);
279 ResumeThread(hThread);
280 if (!success) {
281 fprintf(fp, "Cannot get thread context : 0x0%.8lx\n", GetLastError());
282 return false;
283 }
284 }
285 else {
286 RtlCaptureContext(&context);
287 }
288 return BLI_windows_system_backtrace_run_trace(fp, hThread, &context);
289}
290
292{
293 fprintf(fp, "Loaded Modules :\n");
294 HANDLE hModuleSnap = CreateToolhelp32Snapshot(TH32CS_SNAPMODULE, 0);
295 if (hModuleSnap == INVALID_HANDLE_VALUE) {
296 return;
297 }
298
299 MODULEENTRY32 me32;
300 me32.dwSize = sizeof(MODULEENTRY32);
301
302 if (!Module32First(hModuleSnap, &me32)) {
303 CloseHandle(hModuleSnap); /* Must clean up the snapshot object! */
304 fprintf(fp, " Error getting module list.\n");
305 return;
306 }
307
308 do {
309 if (me32.th32ProcessID == GetCurrentProcessId()) {
310 char version[MAX_PATH];
311 bli_windows_get_module_version(me32.szExePath, version, sizeof(version));
312
313 IMAGEHLP_MODULE64 m64;
314 m64.SizeOfStruct = sizeof(m64);
315 if (SymGetModuleInfo64(GetCurrentProcess(), (DWORD64)me32.modBaseAddr, &m64)) {
316 fprintf(fp,
317 "0x%p %-20s %s %s %s\n",
318 me32.modBaseAddr,
319 version,
320 me32.szModule,
321 m64.LoadedPdbName,
322 m64.PdbUnmatched ? "[unmatched]" : "");
323 }
324 else {
325 fprintf(fp, "0x%p %-20s %s\n", me32.modBaseAddr, version, me32.szModule);
326 }
327 }
328 } while (Module32Next(hModuleSnap, &me32));
329}
330
332{
333 fprintf(fp, "Threads:\n");
334 HANDLE hThreadSnap = INVALID_HANDLE_VALUE;
335 THREADENTRY32 te32;
336
337 hThreadSnap = CreateToolhelp32Snapshot(TH32CS_SNAPTHREAD, 0);
338 if (hThreadSnap == INVALID_HANDLE_VALUE) {
339 fprintf(fp, "Unable to retrieve threads list.\n");
340 return;
341 }
342
343 te32.dwSize = sizeof(THREADENTRY32);
344
345 if (!Thread32First(hThreadSnap, &te32)) {
346 CloseHandle(hThreadSnap);
347 return;
348 }
349 do {
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);
355 CloseHandle(ht);
356 }
357 }
358 } while (Thread32Next(hThreadSnap, &te32));
359 CloseHandle(hThreadSnap);
360}
361
362static bool bli_windows_system_backtrace_stack(FILE *fp, const EXCEPTION_POINTERS *exception_info)
363{
364 fprintf(fp, "Stack trace:\n");
365 /* If we are handling an exception use the context record from that. */
366 if (exception_info && exception_info->ExceptionRecord->ExceptionAddress) {
367 /* The back trace code will write to the context record, to protect the original record from
368 * modifications give the backtrace a copy to work on. */
369 CONTEXT TempContext = *exception_info->ContextRecord;
370 return BLI_windows_system_backtrace_run_trace(fp, GetCurrentThread(), &TempContext);
371 }
372 else {
373 /* If there is no current exception or the address is not set, walk the current stack. */
374 return bli_windows_system_backtrace_stack_thread(fp, GetCurrentThread());
375 }
376}
377
379{
380 IMAGEHLP_MODULE64 m64;
381 m64.SizeOfStruct = sizeof(m64);
382 if (SymGetModuleInfo64(GetCurrentProcess(), (DWORD64)GetModuleHandle(nullptr), &m64)) {
383 return m64.GlobalSymbols;
384 }
385 return false;
386}
387
388static void bli_load_symbols()
389{
390 /* If this is a developer station and the private pdb is already loaded leave it be. */
392 return;
393 }
394
395 char pdb_file[MAX_PATH] = {0};
396
397 /* get the currently executing image */
398 if (GetModuleFileNameA(nullptr, pdb_file, sizeof(pdb_file))) {
399 /* remove the filename */
400 PathRemoveFileSpecA(pdb_file);
401 /* append blender.pdb */
402 PathAppendA(pdb_file, "blender.pdb");
403 if (PathFileExistsA(pdb_file)) {
404 HMODULE mod = GetModuleHandle(nullptr);
405 if (mod) {
406 WIN32_FILE_ATTRIBUTE_DATA file_data;
407 if (GetFileAttributesExA(pdb_file, GetFileExInfoStandard, &file_data)) {
408 /* SymInitialize will try to load symbols on its own, so we first must unload whatever it
409 * did trying to help */
410 SymUnloadModule64(GetCurrentProcess(), (DWORD64)mod);
411
412 DWORD64 module_base = SymLoadModule(GetCurrentProcess(),
413 nullptr,
414 pdb_file,
415 nullptr,
416 (DWORD64)mod,
417 (DWORD)file_data.nFileSizeLow);
418 if (module_base == 0) {
419 fprintf(stderr,
420 "Error loading symbols %s\n\terror:0x%.8lx\n\tsize = %lu\n\tbase=0x%p\n",
421 pdb_file,
422 GetLastError(),
423 file_data.nFileSizeLow,
424 (LPVOID)mod);
425 }
426 }
427 }
428 }
429 }
430}
431
432void BLI_system_backtrace_with_os_info(FILE *fp, const void *os_info)
433{
434 const EXCEPTION_POINTERS *exception_info = static_cast<const EXCEPTION_POINTERS *>(os_info);
435 SymInitialize(GetCurrentProcess(), nullptr, TRUE);
437 if (exception_info) {
438 bli_windows_system_backtrace_exception_record(fp, exception_info->ExceptionRecord);
439 }
440 if (bli_windows_system_backtrace_stack(fp, exception_info)) {
441 /* When the blender symbols are missing the stack traces will be unreliable
442 * so only run if the previous step completed successfully. */
444 }
446}
447
448void BLI_windows_exception_print_message(const void *os_info)
449{
450 if (!os_info) {
451 return;
452 }
453
454 const EXCEPTION_POINTERS *exception = static_cast<const EXCEPTION_POINTERS *>(os_info);
455 const char *exception_name = bli_windows_get_exception_description(
456 exception->ExceptionRecord->ExceptionCode);
457 LPVOID address = exception->ExceptionRecord->ExceptionAddress;
458 CHAR modulename[MAX_PATH];
459 bli_windows_get_module_name(address, modulename, sizeof(modulename));
460 DWORD threadId = GetCurrentThreadId();
461
462 char message[512];
463 BLI_snprintf(message,
464 512,
465 "Error : %s\n"
466 "Address : 0x%p\n"
467 "Module : %s\n"
468 "Thread : %.8x\n",
469 exception_name,
470 address,
471 modulename,
472 threadId);
473
474 fprintf(stderr, "%s", message);
475 fflush(stderr);
476}
477
478/* -------------------------------------------------------------------- */
481
482static std::string get_os_info()
483{
484 OSVERSIONINFOEX osvi;
485 ZeroMemory(&osvi, sizeof(OSVERSIONINFOEX));
486 osvi.dwOSVersionInfoSize = sizeof(OSVERSIONINFOEX);
487 if (!GetVersionEx((OSVERSIONINFO *)&osvi)) {
488 return "Unknown System";
489 }
490
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);
496
497 SYSTEM_INFO si;
498 GetSystemInfo(&si);
499 std::string architecture;
500 switch (si.wProcessorArchitecture) {
501 case PROCESSOR_ARCHITECTURE_AMD64:
502 architecture = "64 Bits";
503 break;
504 case PROCESSOR_ARCHITECTURE_INTEL:
505 architecture = "32 Bits";
506 break;
507 case PROCESSOR_ARCHITECTURE_ARM:
508 architecture = "ARM Architecture";
509 break;
510 case PROCESSOR_ARCHITECTURE_ARM64:
511 architecture = "ARM64 Architecture";
512 break;
513 case PROCESSOR_ARCHITECTURE_ARM32_ON_WIN64:
514 architecture = "ARM32 on Windows 64-bit";
515 break;
516 case PROCESSOR_ARCHITECTURE_IA32_ON_ARM64:
517 architecture = "IA32 on ARM64";
518 break;
519 default:
520 architecture = "Unknown Architecture";
521 }
522
523 return "Windows-" + version + " " + architecture;
524}
525
530static bool bli_executable_path_get(LPWSTR path, DWORD size)
531{
532 wchar_t executable_path[MAX_PATH];
533 DWORD nSize = GetModuleFileNameW(nullptr, executable_path, MAX_PATH);
534 if (nSize == 0 || nSize == MAX_PATH) {
535 return false;
536 }
537
538 if (size <= nSize) {
539 return false;
540 }
541
542 /* Copy the path to the output buffer. */
543 if (wcscpy_s(path, size, executable_path) != 0) {
544 return false;
545 }
546
547 /* Replace the filename "blender.exe" with "blender-launcher.exe". */
548 if (!PathRemoveFileSpecW(executable_path)) {
549 /* Failed to remove the file spec. Use the original path. */
550 return true;
551 }
552 if (!PathAppendW(executable_path, L"blender-launcher.exe")) {
553 /* Failed to append the new filename. Use the original path. */
554 return true;
555 }
556
557 /* Check if "blender-launcher.exe" exists at this path. */
558 DWORD attributes = GetFileAttributesW(executable_path);
559 if (attributes == INVALID_FILE_ATTRIBUTES || (attributes & FILE_ATTRIBUTE_DIRECTORY)) {
560 /* "blender-launcher.exe" does not exist. Use the original executable path. */
561 return true;
562 }
563
564 if (wcslen(executable_path) + 1 > size) {
565 /* The output buffer is not large enough for the new path. Use the original path. */
566 return true;
567 }
568
569 /* The file exists. Copy the path to the output buffer. */
570 if (wcscpy_s(path, size, executable_path) != 0) {
571 /* Error: It's not supposed to happen. Return false since the buffer has been modified. */
572 return false;
573 }
574
575 return true;
576}
577
578/* Wrapper function for url_encode. */
579static std::wstring url_encode_wstring(const std::string &str)
580{
581 size_t len = str.length();
582
583 /* Maximum encoded length is 3 times the original length +1 for null terminator. */
584 size_t encoded_len_max = len * 3 + 1;
585
586 char *encoded_str = new char[encoded_len_max];
587 url_encode(str.c_str(), encoded_str, encoded_len_max);
588
589 /* Convert the encoded char *to a std::wstring (assuming the encoded string is ASCII). */
590 std::wstring result(encoded_str, encoded_str + strlen(encoded_str));
591
592 delete[] encoded_str;
593
594 return result;
595}
596
597void BLI_windows_exception_show_dialog(const char *filepath_crashlog,
598 const char *filepath_relaunch,
599 const char *gpu_name,
600 const char *build_version)
601{
602 /* Redundant: #InitCommonControls is already called during GHOST System initialization. */
603 // InitCommonControls();
604
605 /* Convert file paths to UTF16 to handle non-ASCII characters. */
606 wchar_t *filepath_crashlog_utf16 = alloc_utf16_from_8(filepath_crashlog, 0);
607 wchar_t *filepath_relaunch_utf16 = filepath_relaunch[0] ?
608 alloc_utf16_from_8(filepath_relaunch, 0) :
609 nullptr;
610
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"
614 "\n"
615 L"The crash log can be found at:\n" +
616 std::wstring(filepath_crashlog_utf16);
617
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"}};
623
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;
633 config.cButtons = ARRAY_SIZE(buttons);
634
635 /* Data passed to the callback function for handling button events. */
636 const struct Data {
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);
643
644 /* Callback for handling button events. */
645 config.pfCallback = [](HWND /*hwnd*/,
646 UINT uNotification,
647 WPARAM wParam,
648 LPARAM /*lParam*/,
649 LONG_PTR dwRefData) -> HRESULT {
650 const Data *data_ptr = reinterpret_cast<const Data *>(dwRefData);
651 if (uNotification != TDN_BUTTON_CLICKED) {
652 return S_OK;
653 }
654 int pnButton = static_cast<int>(wParam);
655 switch (pnButton) {
656 case IDCLOSE:
657 return S_OK;
658 case IDRETRY: {
659 /* Relaunch the application. */
660 wchar_t executable_path[MAX_PATH];
661 if (bli_executable_path_get(executable_path, ARRAYSIZE(executable_path))) {
662 std::wstring parameters;
663 if (data_ptr->filepath_relaunch_utf16) {
664 /* Properly quote the argument to handle spaces and special characters. */
665 parameters = L"\"" + std::wstring(data_ptr->filepath_relaunch_utf16) + L"\"";
666 }
667 else {
668 /* Proceeding without parameters. */
669 parameters = L"";
670 }
671 ShellExecuteW(
672 nullptr, L"open", executable_path, parameters.c_str(), nullptr, SW_SHOWNORMAL);
673 }
674 return S_OK;
675 }
676 case IDHELP:
677 /* Open the crash log. */
678 ShellExecuteW(
679 nullptr, L"open", data_ptr->filepath_crashlog_utf16, nullptr, nullptr, SW_SHOWNORMAL);
680 return S_FALSE;
681 case IDOK: {
682 /* Open the bug report form with pre-filled data. */
683 /* clang-format off */
684 std::wstring link =
685 L"https://redirect.blender.org/"
686 L"?type=bug_report"
687 L"&project=blender"
688 L"&os=" + url_encode_wstring(get_os_info()) +
689 L"&gpu=" + url_encode_wstring(data_ptr->gpu_name) +
690 L"&broken_version=" + url_encode_wstring(data_ptr->build_version) +
691 L"&utm_content=crash_dialog";
692 /* clang-format on */
693 ShellExecuteW(nullptr, L"open", link.c_str(), nullptr, nullptr, SW_SHOWNORMAL);
694 return S_FALSE;
695 }
696 default:
697 return S_FALSE;
698 }
699 };
700
701 TaskDialogIndirect(&config, nullptr, nullptr, nullptr);
702 free(static_cast<void *>(filepath_crashlog_utf16));
703 free(static_cast<void *>(filepath_relaunch_utf16));
704}
705
707
708} // namespace blender
Read Blender memory allocation and freeing.
#define str(s)
VecBase< float, D > constexpr mod(VecOp< float, D >, VecOp< float, D >) RET
ccl_device_inline dual1 len(const ccl_private dual< T > &a)
Definition math_dual.h:263
#define L
void free(Subdiv *subdiv)
Definition subdiv.cc:192
BMesh Iterators.
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)
Definition system.cc:73
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)
Definition utfconv.cc:294