WIP: Windows: Show popup after crash #129974

Draft
Germano Cavalcante wants to merge 11 commits from mano-wii/blender:crash_popup into main

When changing the target branch, be careful to rebase the branch in your fork to match. See documentation.

Implements a crash dialog for Windows, showing what was discussed in
#128621


image
Implements a crash dialog for Windows, showing what was discussed in #128621 --- <img width="346" alt="image" src="attachments/142227f6-3c83-41ce-8e93-4e0669daece1">
Germano Cavalcante added 1 commit 2024-11-07 15:45:15 +01:00
Germano Cavalcante changed title from Windows: Show popup after crash to WIP: Windows: Show popup after crash 2024-11-07 15:45:29 +01:00
Germano Cavalcante requested review from Ray molenkamp 2024-11-07 15:45:41 +01:00
Ray molenkamp requested changes 2024-11-07 17:08:23 +01:00
@ -48,2 +48,3 @@
*/
void BLI_windows_handle_exception(void *exception);
void BLI_windows_exception_capture(void *exception);
void bli_windows_exception_message_get(char r_message[512]);
Member

lower case functions do not go in public headers they are reserved for static local functions.

lower case functions do not go in public headers they are reserved for static local functions.
mano-wii marked this conversation as resolved
@ -479,6 +479,7 @@ if(WIN32)
)
list(APPEND SRC
intern/system_win32.c
intern/system_win32.cc
Member

best to convert system_win32.c to C++ in a separate commit/PR.

best to convert system_win32.c to C++ in a separate commit/PR.
Author
Member

Well, that's one point, in this case I created the two files because, for some reason, it was not possible to merge them into just system_win32.cc. There are linking errors. I could convert system_win32.c to C++, but the new functions do not get along well if added to the same file.

Well, that's one point, in this case I created the two files because, for some reason, it was not possible to merge them into just `system_win32.cc`. There are linking errors. I could convert `system_win32.c` to C++, but the new functions do not get along well if added to the same file.
mano-wii marked this conversation as resolved
@ -384,6 +384,7 @@ void BLI_system_backtrace(FILE *fp)
SymInitialize(GetCurrentProcess(), NULL, TRUE);
bli_load_symbols();
if (current_exception) {
/* `BLI_windows_exception_log_start` should have been called before. */
Member

BLI_windows_exception_log_start doesn't exist? you likely mean BLI_windows_exception_capture?

`BLI_windows_exception_log_start` doesn't exist? you likely mean `BLI_windows_exception_capture`?
mano-wii marked this conversation as resolved
@ -395,3 +396,3 @@
}
void BLI_windows_handle_exception(EXCEPTION_POINTERS *exception)
void BLI_windows_exception_capture(void *exception)
Member

Not a fan of this pattern, it gives the opportunity of use after frees that normally wouldn't happen if you just passed the exception as an argument to the functions that require it. Also having a function called bli_windows_exception_message_get not have an exception as input parameter is really strange.

Not a fan of this pattern, it gives the opportunity of use after frees that normally wouldn't happen if you just passed the exception as an argument to the functions that require it. Also having a function called `bli_windows_exception_message_get` not have an exception as input parameter is _really_ strange.
mano-wii marked this conversation as resolved
@ -414,1 +401,3 @@
fflush(stderr);
}
void bli_windows_exception_message_get(char r_message[512])
Member

lower case bli_ prefix, but not a static function

lower case `bli_` prefix, but not a static function
mano-wii marked this conversation as resolved
@ -415,0 +403,4 @@
void bli_windows_exception_message_get(char r_message[512])
{
if (!current_exception) {
/* `BLI_windows_exception_log_start` should have been called before. */
Member

BLI_windows_exception_log_start doesn't exist? you likely mean BLI_windows_exception_capture?

`BLI_windows_exception_log_start` doesn't exist? you likely mean `BLI_windows_exception_capture`?
mano-wii marked this conversation as resolved
@ -415,0 +417,4 @@
snprintf(r_message,
512,
"Error : %s\n"
Member

This is more of a UI issue, who is this data for?

If it's for us developers, i'd probably want the ExceptionFlags and any Parameters to be included.

If it's for the end user, there's no need to have the Address and TreadID fields here, as there's literally nothing useful the user can do with that information.

This is more of a UI issue, who is this data for? If it's for us developers, i'd probably want the ExceptionFlags and any Parameters to be included. If it's for the end user, there's no need to have the Address and TreadID fields here, as there's literally nothing useful the user can do with that information.
Author
Member

I decided to remove this information from the popup. It wasn't part of the mockup. It was an artistic liberty but it ended up looking ugly.

I decided to remove this information from the popup. It wasn't part of the mockup. It was an artistic liberty but it ended up looking ugly.
mano-wii marked this conversation as resolved
@ -0,0 +19,4 @@
/** \name showMessageBox
* \{ */
static std::string url_encode(const char *str)
Member

This should probably live elsewhere, seems like a useful function outside of system_win32 if we're keeping it here, why not just call the UrlEscape API? input a const char*, output a string feels strange

This should probably live elsewhere, seems like a useful function outside of `system_win32` if we're keeping it here, why not just call the `UrlEscape` API? input a const char*, output a string feels strange
Author
Member

...why not just call the UrlEscape API?

I don't know what I'm doing wrong, but it's not working:

static std::string url_encode(const std::string &str)
{
  /* Query required buffer size. */
  DWORD size = 0;
  UrlEscapeA(str.c_str(), nullptr, &size, URL_ESCAPE_PERCENT);

  /* Perform actual URL encoding. */
  std::vector<char> buffer(size + 1);
  UrlEscapeA(str.c_str(), buffer.data(), &size, URL_ESCAPE_PERCENT);
  return std::string(buffer.data());
}

This code is a bit difficult to debug, so I didn't investigate it, but even so, I have a slight preference for a solution that doesn't use the Windows API since perhaps this code could be exposed later in some BLI header.

> ...why not just call the `UrlEscape` API? I don't know what I'm doing wrong, but it's not working: ```cpp static std::string url_encode(const std::string &str) { /* Query required buffer size. */ DWORD size = 0; UrlEscapeA(str.c_str(), nullptr, &size, URL_ESCAPE_PERCENT); /* Perform actual URL encoding. */ std::vector<char> buffer(size + 1); UrlEscapeA(str.c_str(), buffer.data(), &size, URL_ESCAPE_PERCENT); return std::string(buffer.data()); } ``` This code is a bit difficult to debug, so I didn't investigate it, but even so, I have a slight preference for a solution that doesn't use the Windows API since perhaps this code could be exposed later in some BLI header.
@ -0,0 +85,4 @@
* Displays a crash popup with options to open the crash log and report a bug.
* This is based on the `showMessageBox` function in `GHOST_SystemWin32.cc`.
*/
static void showMessageBox(const char *message,
Member

missing bli_ prefix

missing `bli_` prefix
mano-wii marked this conversation as resolved
@ -82,3 +85,3 @@
}
static void sig_handle_crash_backtrace(FILE *fp)
static void crashlog_filepath_get(char filepath[FILE_MAX])
Member

Not convinced this belongs in this file, all other methods are either MAIN_ or sig_ this feels a bit out of place? @ideasman42 do you have any strong feelings about this?

Not convinced this belongs in this file, all other methods are either `MAIN_` or `sig_` this feels a bit out of place? @ideasman42 do you have any strong feelings about this?
@ -147,2 +148,4 @@
}
}
static void signal_cleanup_and_terminate(int signum)
Member

all other code around here uses sig_

all other code around here uses `sig_`
mano-wii marked this conversation as resolved
Ray molenkamp requested review from Harley Acheson 2024-11-07 17:08:53 +01:00
Member

I'd like @Harley to sign off on the user facing changes, so added him as reviewer.

I'd like @Harley to sign off on the user facing changes, so added him as reviewer.
Germano Cavalcante added 4 commits 2024-11-09 01:04:12 +01:00
Germano Cavalcante added 1 commit 2024-11-09 01:10:19 +01:00
Germano Cavalcante added 1 commit 2024-11-09 01:16:25 +01:00
Avoid reopening a .blend file that was not saved during the session. This can cause an infinite loop if the crash occurs when opening Blender.
All checks were successful
buildbot/vexp-code-patch-lint Build done.
buildbot/vexp-code-patch-darwin-x86_64 Build done.
buildbot/vexp-code-patch-linux-x86_64 Build done.
buildbot/vexp-code-patch-darwin-arm64 Build done.
buildbot/vexp-code-patch-windows-amd64 Build done.
buildbot/vexp-code-patch-coordinator Build done.
4b141088e7
Author
Member

I implemented the solution of opening the last saved .blend. (For this I just stored the directory in G.filepath_last_blend whenever a .blend file is written for autosave or for save).

(This is not something that has been discussed much, it can be reversed or postponed if fells unsafe).

@blender-bot build

I implemented the solution of opening the last saved .blend. (For this I just stored the directory in `G.filepath_last_blend` whenever a .blend file is written for autosave or for save). (This is not something that has been discussed much, it can be reversed or postponed if fells unsafe). @blender-bot build
Member

I'll leave that to the UI team, at face value, it is a little strange that a button labelled "close" would open a new blender

I'll leave that to the UI team, at face value, it is a little strange that a button labelled "close" would open a new blender

I think you're going to have to process the filepath differently, converting directly to wstring like that won't work. This is what results when crashing a file called こんにちは.blend :
image

I think you'll need to the UTF16_ENCODE and UTF16_UN_ENCODE macros.

I think you're going to have to process the filepath differently, converting directly to `wstring` like that won't work. This is what results when crashing a file called `こんにちは.blend` : <img width="275" alt="image" src="attachments/8f98925d-2ce4-4f90-9a23-85c8c72deeaa"> I think you'll need to the `UTF16_ENCODE` and `UTF16_UN_ENCODE` macros.
Germano Cavalcante added 4 commits 2024-11-11 13:38:19 +01:00
Author
Member

Well noted @deadpin, fixed :)
(I preferred to use the same solution seen in the original showMessageBox).

Well noted @deadpin, fixed :) (I preferred to use the same solution seen in the original `showMessageBox`).
This pull request is marked as a work in progress.

Checkout

From your project repository, check out a new branch and test the changes.
git fetch -u crash_popup:mano-wii-crash_popup
git checkout mano-wii-crash_popup
Sign in to join this conversation.
No Label
Interest
Alembic
Interest
Animation & Rigging
Interest
Asset System
Interest
Audio
Interest
Automated Testing
Interest
Blender Asset Bundle
Interest
BlendFile
Interest
Code Documentation
Interest
Collada
Interest
Compatibility
Interest
Compositing
Interest
Core
Interest
Cycles
Interest
Dependency Graph
Interest
Development Management
Interest
EEVEE
Interest
Freestyle
Interest
Geometry Nodes
Interest
Grease Pencil
Interest
ID Management
Interest
Images & Movies
Interest
Import Export
Interest
Line Art
Interest
Masking
Interest
Metal
Interest
Modeling
Interest
Modifiers
Interest
Motion Tracking
Interest
Nodes & Physics
Interest
OpenGL
Interest
Overlay
Interest
Overrides
Interest
Performance
Interest
Physics
Interest
Pipeline, Assets & IO
Interest
Platforms, Builds & Tests
Interest
Python API
Interest
Render & Cycles
Interest
Render Pipeline
Interest
Sculpt, Paint & Texture
Interest
Text Editor
Interest
Translations
Interest
Triaging
Interest
Undo
Interest
USD
Interest
User Interface
Interest
UV Editing
Interest
VFX & Video
Interest
Video Sequencer
Interest
Viewport & EEVEE
Interest
Virtual Reality
Interest
Vulkan
Interest
Wayland
Interest
Workbench
Interest: X11
Legacy
Asset Browser Project
Legacy
Blender 2.8 Project
Legacy
Milestone 1: Basic, Local Asset Browser
Legacy
OpenGL Error
Meta
Good First Issue
Meta
Papercut
Meta
Retrospective
Meta
Security
Module
Animation & Rigging
Module
Core
Module
Development Management
Module
Grease Pencil
Module
Modeling
Module
Nodes & Physics
Module
Pipeline, Assets & IO
Module
Platforms, Builds & Tests
Module
Python API
Module
Render & Cycles
Module
Sculpt, Paint & Texture
Module
Triaging
Module
User Interface
Module
VFX & Video
Module
Viewport & EEVEE
Platform
FreeBSD
Platform
Linux
Platform
macOS
Platform
Windows
Severity
High
Severity
Low
Severity
Normal
Severity
Unbreak Now!
Status
Archived
Status
Confirmed
Status
Duplicate
Status
Needs Info from Developers
Status
Needs Information from User
Status
Needs Triage
Status
Resolved
Type
Bug
Type
Design
Type
Known Issue
Type
Patch
Type
Report
Type
To Do
No Milestone
No project
No Assignees
3 Participants
Notifications
Due Date
The due date is invalid or out of range. Please use the format 'yyyy-mm-dd'.

No due date set.

Dependencies

No dependencies set.

Reference: blender/blender#129974
No description provided.