Page MenuHome

Fix crash after opening fileselctor twice
Needs RevisionPublic

Authored by Jake (Welp) on Sep 22 2021, 1:56 AM.

Details

Summary

Fixes T88570

If the fileselect is going to be created in a reused window, attach to parent to prevent crash. Remove check for single area. Tag fileselect for refresh to ensure UI updates when area reused.

Scenarios tested:

  • Ctrl+S
  • Ctrl+S, Ctrl+S
  • Open any other fileselect (e.g. Ctrl+O or Alt+S), Ctrl+S. Fileselect is reused and updated to Save options.
  • Open any fileselect, split area, Ctrl+S.
  • Open any fileselect, split area, close original area, Ctrl+S. New window is opened.
  • Open another type of temp window (e.g. "Render Image") and switch the editor to file browser, Ctrl+S. Area is reused for save dialog, and area is returned to it's original type without issue when Save or Cancel is chosen.

Diff Detail

Repository
rB Blender
Branch
Fix-Fileselect-Crash (branched from master)
Build Status
Buildable 17527
Build 17527: arc lint + arc unit

Event Timeline

Jake (Welp) requested review of this revision.Sep 22 2021, 1:56 AM
Jake (Welp) created this revision.
Jake (Welp) edited the summary of this revision. (Show Details)Sep 22 2021, 2:19 AM
Jake (Welp) edited the summary of this revision. (Show Details)Sep 22 2021, 2:45 AM
Jake (Welp) added a reviewer: User Interface.
Jake (Welp) added a project: User Interface.

I have a feeling this is close, but not quite...

The problem here isn't the resuse of temporary windows, but that a second call to WM_window_open is even made.

I think you can take your changes here, replace the win = win->parent; with return; then change the comment to something like "Do not open new File Browser if one is already open."

Having said that it is very possible that your code could further be reduced to:

/* Do not open new File Browser if one is already open. */
if (CTX_wm_space_file(C)) {
  return;
}

I don't think there are any situations where this would not work well, but worth checking.

I think you can take your changes here, replace the win = win->parent; with return; then change the comment to something like "Do not open new File Browser if one is already open."

The difference would be that if a fileselector was open and you chose a different operator that uses a file selector, say Alt+S for image save followed by Ctrl+Alt+S, returning immediately would mean the fileselctor wouldn't update from the image save to the mainfile save dialog, effectively disabling other operators that use a fileselector until the existing one is closed.

Having said that it is very possible that your code could further be reduced to:
I don't think there are any situations where this would not work well, but worth checking.

The only way I think this could cause an issue is in cases where a SPACE_FILE is not the only space in the window, and I don't see anywhere that could happen... updated, thanks!

This comment was removed by Harley Acheson (harley).

I'd add a check that win->parent is not null but otherwise looks good to me.

/* If this is a File Browser window, handlers go in the parent. */
if (CTX_wm_space_file(C) && win->parent) {
  win = win->parent;
}

Noticed that CTX_wm_space_file() returns NULL if the space isn't currently under the cursor, meaning that it doesn't guard from the crash reliably. The first solution doesn't have this issue, so reverting to that.

  • Revert to working solution
Campbell Barton (campbellbarton) requested changes to this revision.Sep 24 2021, 9:21 AM
Campbell Barton (campbellbarton) added inline comments.
source/blender/windowmanager/intern/wm_event_system.c
3579โ€“3580

Checking the area type / number of areas isn't reliable.

It's possible to redo the crash with this patch applied by splitting the area of an open file-selector.

Suggest to keep selecting parent windows until the window doesn't have a temporary screen (ignoring the area type).

This revision now requires changes to proceed.Sep 24 2021, 9:21 AM

This is still letting that second WM_window_open proceed. So do the following:

  • Edit / Preferences / File Paths
  • Click on a folder icon to change any path
  • Hit Ctrl-S while that window is open, see that "Accept" button changes to "Save Blender File".

Doing an early exit (my first comment) fixes this but then breaks other things.

The fix has to address both issues otherwise I'd rather just tell people "don't hit ctrl-s twice"

Jake (Welp) updated this revision to Diff 42851.Oct 3 2021, 5:00 PM

Remove single area check, add null check and refresh

Jake (Welp) edited the summary of this revision. (Show Details)Oct 3 2021, 5:10 PM

Still behaves oddly, as described in my earlier comment about "Edit / Preferences / File Paths"

I can't see that this "wm_window.c" change is doing anything for you here. When asked to create a new window we are looking at the existing ones in case we don't want to make a second copy of one that isn't meant to have multiples. The existing logic is "don't make a new window if there is one that is temp, and has just a single editor matching the one being asked for". I can't see how relaxing the "has just a single editor" helps with the issue at hand, unless I am missing something.

To be honest, I don't think the solution to this problem will be related to File Browser window creation at all. You might need to back up one layer or so...

Using current master, open an EXISTING file, so one that already has a file name. Hit ctrl-S and see that it just saves without a bringing up a dialog. Now select "File / Save As" to bring up the File Browser. While that is up, hit Ctrl-S and see that the file is saved, properly, and without causing any kind of error, even though the "Save As" File Browser is already open.

The reported error occurs when the file has not been previously saved. This is because "Save" and "Save as" are different operators (save_mainfile and save_as_mainfile) that share some functions between them. If you look at wm_save_mainfile_invoke you will see where we check if the file has a name (G.save_over) and either just immediately saves, or calls WM_event_add_fileselect. You could probably just put your checks there to see if there is already a File Save happening. checking there won't affect other uses of the File Browser since this only for saving the main file.

So my gut feeling is that something as simple as this might be enough:

source/blender/windowmanager/intern/wm_event_system.c
3579โ€“3580

From looking into applying this change it doesn't solve the bug in all cases.

Campbell Barton (campbellbarton) requested changes to this revision.Oct 4 2021, 1:40 AM

Requesting changes as the crash still happens with this patch.

This revision now requires changes to proceed.Oct 4 2021, 1:40 AM

@Jake (Welp) - Did a few quick tests with my idea of just checking for CTX_wm_space_file inside wm_save_mainfile_invoke and not finding any problems even in all the odd circumstances I could think of. I am assuming though that you've gotten quite good at testing this now, so maybe you will find a problem situation I am missing or you can confirm it is working for you.

Requesting changes as the crash still happens with this patch.

Could you list the steps to cause the crash?

As pointed out my suggested patch above would not detect a running File Browser in a window when your mouse is over a different window. The following should check for that but also if it is open as a maximized temporary area in the main window.

As pointed out my suggested patch above would not detect a running File Browser in a window when your mouse is over a different window. The following should check for that but also if it is open as a maximized temporary area in the main window.

If you have an open File Browser area, and place the cursor within the area, Ctrl+S will not function. The crash is also still present with other operators such as open_mainfile and recover_auto_save.

@Jake (Welp) - If you have an open File Browser area, and place the cursor within the area, Ctrl+S will not function.

Yes, that is just caught by that if (CTX_wm_space_file(C)) test. Since this issue does not seem to happen when opening the file browser as a maximized area you could just take that out...

Just trying to offer you suggestions.

@Jake (Welp) - The crash is also still present with other operators such as open_mainfile and recover_auto_save.

Here is using that check as a poll function and using it with those other operators:

Changing the file operation while browsing is a feature, not a bug. So you can for example do File โ†’ Open, decide that you want to save the file first and do that using Ctrl+S with the File Browser already open. Or say you decide to make a backup while browsing for a media file. There is plenty of code to make sure that works fine. So this shouldn't be fixed via the poll functions. The File Browser handler code should handle this case properly and replace the file operation.

Julian Eisel (Severin) added a comment.EditedDec 1 2021, 7:03 PM

Looking into this today, I decided to do some further reaching changes to really get to the root of the issue. Submitted D13441: Fix T88570: Crash when saving after pressing ctrl+S twice.. This attempts to properly define rules for how the parent window of a file operation is selected and how we deal with context in return.

We can keep this patch open, since it's not said yet that my patch doesn't cause more problems. First off I need some feedback on it from other devs, to see if they agree with my design. My patch also shouldn't be included in 3.0, it's too risky.

source/blender/windowmanager/intern/wm_window.c
816

I think this is there so we don't reuse windows that contain an edited screen. Not a bullet proof test, but can avoid some annoyances.

Jake (Welp) added inline comments.Dec 2 2021, 12:47 AM
source/blender/windowmanager/intern/wm_window.c
816

I removed this originally because it caused crashes when pressing Ctrl+S after splitting the save area. The only ways I thought of to fix it was this, disabling the ability to alter the temp window, or recording the "type" of temp window.

Thinking about it again though, do you think putting this check back, but making it so altering a temp window (adding/removing spaces, changing space types...) removes its temp status would be a good idea? It would solve the crash, but leave the stricter matching.

source/blender/windowmanager/intern/wm_window.c
816

Editing of temp screens should be disabled, see rB87aca8bd02bc. Unfortunately that commit didn't nearly cover all cases.

There's also code already to prevent other edits to temp screens, like changing the workspace or screen. I would suggest we treat that as a separate issue.

Jake (Welp) added inline comments.Dec 2 2021, 7:23 PM
source/blender/windowmanager/intern/wm_window.c
816

Alright, I'll put together a more complete disabling of editing temp screens in another patch, but until then the removal of the check is necessary to prevent some crashes in some edge cases.

I talked to Campbell a while back and found that the crash he had was not related (fixed in rBd649b4b066f4).