Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Rebuild the profile nav via MenuItemsSource; mitigate a crash #14630

Merged
merged 5 commits into from
Mar 16, 2023

Conversation

zadjii-msft
Copy link
Member

@zadjii-msft zadjii-msft commented Jan 4, 2023

Directly manipulating the NavigationView::MenuItems vector is bad. If you do that, you're gonna get crashes, in WinUI code for Measure. However, a WinUI PR (below) gave me an idea: Changing NavigationView::MenuItemsSource will wholly invalidate the entirety of the nav view items, and that will avoid the crash.

This code does that. It's a wee bit janky, but it works.

Closes #13673

might affect #12333, need to try and repro.

See also:

@ghost ghost added Area-Settings Issues related to settings and customizability, for console or terminal Issue-Bug It either shouldn't be doing this or needs an investigation. Priority-1 A description (P1) Product-Terminal The new Windows Terminal. Severity-Crash Crashes are real bad news. labels Jan 4, 2023
@github-actions

This comment has been minimized.

@zadjii-msft zadjii-msft changed the title Rebuild the profile nave view items via MenuItemsSource, to mitigate a crash Rebuild the profile nav view items via MenuItemsSource, to mitigate a crash Jan 6, 2023
@zadjii-msft zadjii-msft added this to the Terminal v1.17 milestone Jan 10, 2023
Copy link
Member

@carlos-zamora carlos-zamora left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sure, if it works, it works haha. The ReplaceAll() we were doing was also a workaround so at this point I'll take what I can get :P

src/cascadia/TerminalSettingsEditor/MainPage.cpp Outdated Show resolved Hide resolved
src/cascadia/TerminalSettingsEditor/MainPage.cpp Outdated Show resolved Hide resolved
src/cascadia/TerminalSettingsEditor/MainPage.cpp Outdated Show resolved Hide resolved
src/cascadia/TerminalSettingsEditor/MainPage.cpp Outdated Show resolved Hide resolved
@carlos-zamora carlos-zamora added the Needs-Second It's a PR that needs another sign-off label Jan 11, 2023
@ghost ghost requested review from PankajBhojwani, DHowett and lhecker January 11, 2023 01:01
@@ -527,7 +536,7 @@ namespace winrt::Microsoft::Terminal::Settings::Editor::implementation

void MainPage::_InitializeProfilesList()
{
const auto menuItems = SettingsNav().MenuItems();
const auto menuItems = SettingsNav().MenuItemsSource().try_as<Windows::Foundation::Collections::IVector<IInspectable>>();
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This introduces an ordering dependency, right? It seems like there is code that can run before MenuItemsSource is set and code that can only run after. Are we clear on what happens here if somehow it's not been set?

@@ -555,6 +564,30 @@ namespace winrt::Microsoft::Terminal::Settings::Editor::implementation
menuItems.Append(addProfileItem);
}

void MainPage::_SetupNavViewItems()
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

For clarity, I might recommend we be very specific about what this does.

_moveXAMLParsedNavItemsIntoItemSource

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In fact, we should make it a debug assert that it never fires twice

@ghost ghost added the Needs-Author-Feedback The original author of the issue/PR needs to come back and respond to something label Jan 11, 2023
carlos-zamora added a commit that referenced this pull request Jan 14, 2023
@ghost ghost removed the Needs-Author-Feedback The original author of the issue/PR needs to come back and respond to something label Jan 17, 2023
@zadjii-msft zadjii-msft self-assigned this Jan 29, 2023
@microsoft-github-policy-service microsoft-github-policy-service bot removed the Needs-Second It's a PR that needs another sign-off label Mar 9, 2023
@DHowett DHowett changed the title Rebuild the profile nav view items via MenuItemsSource, to mitigate a crash Rebuild the profile nav via MenuItemsSource; mitigate a crash Mar 16, 2023
@DHowett DHowett merged commit 8c17475 into main Mar 16, 2023
@DHowett DHowett deleted the dev/migrie/b/13673-winui-is-horrible branch March 16, 2023 20:41
DHowett pushed a commit that referenced this pull request Mar 31, 2023
Directly manipulating the `NavigationView::MenuItems` vector is bad. If
you do that, you're gonna get crashes, in WinUI code for `Measure`.
However, a WinUI PR (below) gave me an idea: Changing
`NavigationView::MenuItemsSource` will wholly invalidate the entirety of
the nav view items, and that will avoid the crash.

This code does that. It's a wee bit janky, but it works.

Closes #13673

_might_ affect #12333, need to try and repro.

See also:
* #9273
* #10390
* microsoft/microsoft-ui-xaml#6302
* microsoft/microsoft-ui-xaml#3138, which was
the fix for microsoft/microsoft-ui-xaml#2818

(cherry picked from commit 8c17475)
Service-Card-Id: 88428128
Service-Version: 1.17
zadjii-msft added a commit that referenced this pull request Apr 17, 2023
* make the list of MenuItems observable, so the nav view can actually
listen for changes to it
* Use the MenuItemsSource to find the index to add at, rather than the
MenuItems (which isn't accurate anymore)
* Stash a single observable vector as the menuitemsource, and modify
that whenever we need to do modifications.
* I attempted to create a new vector, then copy into the new one, then
replace the MenuItemsSource with the new vector, but that _refused_ to
work. So let's just... not.

Regressed in #14630
Closes #15140

Manually validated that this and #13673 are still fixed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Area-Settings Issues related to settings and customizability, for console or terminal Issue-Bug It either shouldn't be doing this or needs an investigation. Priority-1 A description (P1) Product-Terminal The new Windows Terminal. Severity-Crash Crashes are real bad news.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Windows Terminal crashes when emptying settings.json with settings window open
4 participants