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

Fix issue with setting SelectedItem on TreeView would crash application #3136

Conversation

marcelwgn
Copy link
Collaborator

Description

The issue is that SelectedItem might be null in some cases which we didn't anticipate. Added a nullcheck to the selecteditems to guard against this.

The brackets were added to improve readability.

Motivation and Context

Fixes #3129

How Has This Been Tested?

Add new API test.

Screenshots (if appropriate):

@msft-github-bot msft-github-bot added the needs-triage Issue needs to be triaged by the area owners label Aug 15, 2020
@@ -264,7 +264,7 @@ void TreeView::OnPropertyChanged(const winrt::DependencyPropertyChangedEventArgs
{

const auto items = SelectedItems();
const auto selected = items.Size() > 0 ? items.GetAt(0) : nullptr;
const auto selected = (items != nullptr && items.Size() > 0) ? items.GetAt(0) : nullptr;
Copy link
Contributor

Choose a reason for hiding this comment

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

items != nullptr [](start = 31, length = 16)

Under what circumstances is this null?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

It seems that SelectedItems returns null when TreeView can't resolve it's listcontrol.

Copy link
Contributor

Choose a reason for hiding this comment

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

and what causes that to happen?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

SelectedItems returns null if the internal listview can't be found or the listviews ListViewModel can't be found. So in #3129, we probably crashed due to the binding resolving before the template was applied leaving us in a state where we did not have a listview or selectionmodel.

@StephenLPeters
Copy link
Contributor

/azp run

@azure-pipelines
Copy link

Azure Pipelines successfully started running 1 pipeline(s).

@StephenLPeters StephenLPeters added area-TreeView team-Controls Issue for the Controls team and removed needs-triage Issue needs to be triaged by the area owners labels Aug 17, 2020
@StephenLPeters
Copy link
Contributor

@chingucoding can you merge master to pick up the CI build fix that just went in?

@marcelwgn
Copy link
Collaborator Author

@StephenLPeters This and all other opens PR I created are up to date now.

@StephenLPeters
Copy link
Contributor

/azp run

@azure-pipelines
Copy link

Azure Pipelines successfully started running 1 pipeline(s).

@StephenLPeters
Copy link
Contributor

/azp run

@azure-pipelines
Copy link

Azure Pipelines successfully started running 1 pipeline(s).

@sis2004
Copy link

sis2004 commented Aug 27, 2020

Any ETA on when this will be available?

Copy link
Contributor

@StephenLPeters StephenLPeters left a comment

Choose a reason for hiding this comment

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

:shipit:

@StephenLPeters StephenLPeters merged commit 986d48a into microsoft:master Aug 31, 2020
@StephenLPeters
Copy link
Contributor

StephenLPeters commented Aug 31, 2020

Any ETA on when this will be available?

@sis2004 I just merged this into the repository so it will be included in the next versions. I'd guess there will be a prerelease version made during September, when it is the bot will post on the original issue that it was included in the package.

@sis2004
Copy link

sis2004 commented Aug 31, 2020

@StephenLPeters thanks, I'll keep an eye out for it.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area-TreeView team-Controls Issue for the Controls team
Projects
None yet
Development

Successfully merging this pull request may close these issues.

TreeView - AccessViolationException with SelectedItem
4 participants