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

Setting a value of NaN to StaggeredLayout.DesiredColumnWidth will cause the app to become unresponsive #4063

Closed
1 of 2 tasks
winston-de opened this issue Jun 4, 2021 · 7 comments · Fixed by #4064
Closed
1 of 2 tasks
Labels
Milestone

Comments

@winston-de
Copy link
Contributor

Describe the bug

Setting a value of NaN for StaggeredLayout.DesiredColumnWidth will cause the app to become unresponsive. Sometimes it will even give the good ol' " has stopped responding" dialog.

  • Is this bug a regression in the toolkit? If so, what toolkit version did you last see it work:

Steps to Reproduce

  • Can this be reproduced in the Sample App? (Either in a sample as-is or with new XAML pasted in the editor.) If so, please provide custom XAML or steps to reproduce. If not, let us know why it can't be reproduced (e.g. more complex setup, environment, dependencies, etc...)

Steps to reproduce the behavior:

  1. Go to staggered layout control
  2. Go to xaml tab
  3. Find the staggered layout definition, and set DesiredColumnWidth to NaN
  4. App will become unresponsive, and will eventually crash
<controls:StaggeredLayout DesiredColumnWidth="NaN"
                          ColumnSpacing="5"
                          RowSpacing="5"/>

Expected behavior

If using NaN is not possible, there should be an exception or notification that says this. Also, I don't see anything in the docs about NaN being an invalid parameter.

Screenshots

2021-06-04-113729_Trim.mp4

Environment

NuGet Package(s):

Package Version(s):

Windows 10 Build Number:
- [ ] Fall Creators Update (16299)
- [ ] April 2018 Update (17134)
- [ ] October 2018 Update (17763)
- [ ] May 2019 Update (18362)
- [ ] May 2020 Update (19041)
- [x] Insider Build (build number: 19043.1023)

App min and target version:
- [ ] Fall Creators Update (16299)
- [ ] April 2018 Update (17134)
- [ ] October 2018 Update (17763)
- [ ] May 2019 Update (18362)
- [ ] May 2020 Update (19041)
- [ ] Insider Build (xxxxx)

Device form factor:
- [x] Desktop
- [ ] Xbox
- [ ] Surface Hub
- [ ] IoT

Visual Studio
- [ ] 2017 (version: )
- [ ] 2019 (version: )
- [ ] 2019 Preview (version: )

Additional context

Add any other context about the problem here.

@winston-de winston-de added the bug 🐛 An unexpected issue that highlights incorrect behavior label Jun 4, 2021
@ghost ghost added the needs triage 🔍 label Jun 4, 2021
@ghost
Copy link

ghost commented Jun 4, 2021

Hello winston-de, thank you for opening an issue with us!

I have automatically added a "needs triage" label to help get things started. Our team will analyze and investigate the issue, and escalate it to the relevant team if possible. Other community members may also look into the issue and provide feedback 🙌

@Kyaa-dost
Copy link
Contributor

@winston-de Thanks for the highlight! I am able to repro this as well. Do you want to work on this and create a PR?

@winston-de
Copy link
Contributor Author

@Kyaa-dost Sure!

@Rosuavio
Copy link
Contributor

This is relevant to the issue discussion as well. #4064 (comment)

@Rosuavio
Copy link
Contributor

I tried setting StaggeredLayout.DesiredColumnWidth to NaN on the sample app from the store and it crashed instead of becoming unresponsive. Its an issue either way, the sample app should show the error from sample without crashing or freezing.

@michael-hawker
Copy link
Member

@winston-de I think the root of the question is why you're trying to use NaN as a value, I find that pretty unusual. I know it works in the panel scenario, but then I'd argue why are you trying to use the Panel like that as then it's just a vertical layout?

Can you elaborate a bit on your main objective/scenario behind this issue (vs. from a technical viewpoint)? Thanks.

@skendrot any thoughts on this in general? Regardless of the reasoning, I'm not sure why it works for the Panel but not the Layout.

@winston-de
Copy link
Contributor Author

Can you elaborate a bit on your main objective/scenario behind this issue (vs. from a technical viewpoint)? Thanks.

@michael-hawker I have no use for this, I just figured the unhandled exception was not the intended behavior, and in my pr implemented what I presumed to be the expected behavior. However, I can imagine that NaN could be passed in instances where the column size is bound to a NumberBox's value property.

michael-hawker added a commit to winston-de/WindowsCommunityToolkit that referenced this issue Jun 29, 2021
@ghost ghost closed this as completed in #4064 Jun 29, 2021
ghost pushed a commit that referenced this issue Jun 29, 2021
…e an exception (#4064)

<!-- 🚨 Please Do Not skip any instructions and information mentioned below as they are all required and essential to evaluate and test the PR. By fulfilling all the required information you will be able to reduce the volume of questions and most likely help merge the PR faster 🚨 -->

<!-- 👉 It is imperative to resolve ONE ISSUE PER PR and avoid making multiple changes unless the changes interrelate with each other --> 

<!-- 📝 Please always keep the "☑️ Allow edits by maintainers" button checked in the Pull Request Template as it increases collaboration with the Toolkit maintainers by permitting commits to your PR branch (only) created from your fork. This can let us quickly make fixes for minor typos or forgotten StyleCop issues during review without needing to wait on you doing extra work. Let us help you help us! 🎉 -->


## Fixes #4063 
<!-- Add the relevant issue number after the "#" mentioned above (for ex: "## Fixes #1234") which will automatically close the issue once the PR is merged. -->

<!-- Add a brief overview here of the feature/bug & fix. -->
The exception was caused by having ``NaN`` the value of width in ``item.Element.Measure``. This PR fixes this by adding a check if ``DesiredColumnWidth`` is ``NaN``, and if so setting it instead to the available width.

## PR Type

<!-- Please uncomment one or more options below that apply to this PR. -->

Bugfix
<!-- - Feature -->
<!-- - Code style update (formatting) -->
<!-- - Refactoring (no functional changes, no api changes) -->
<!-- - Build or CI related changes -->
<!-- - Documentation content changes -->
<!-- - Sample app changes -->
<!-- - Other... Please describe: -->


## What is the current behavior?
When ``DesiredColumnWidth`` is ``NaN``,  an exception will be thrown when measuring item sizes, which causes a crash or will freeze the app.

## What is the new behavior?
If ``DesiredColumnWidth`` is ``NaN``, items are stretched to fit the available width.
Example:
![image](https://user-images.githubusercontent.com/59544401/120867269-6eaac500-c546-11eb-91e1-a2caad418212.png)


## PR Checklist

Please check if your PR fulfills the following requirements:

- [x] Tested code with current [supported SDKs](../readme.md#supported)
- [ ] Pull Request has been submitted to the documentation repository [instructions](..\contributing.md#docs). Link: <!-- docs PR link -->
- [ ] Sample in sample app has been added / updated (for bug fixes / features)
    - [ ] Icon has been created (if new sample) following the [Thumbnail Style Guide and templates](https://github.com/windows-toolkit/WindowsCommunityToolkit-design-assets)
- [ ] New major technical changes in the toolkit have or will be added to the [Wiki](https://github.com/windows-toolkit/WindowsCommunityToolkit/wiki) e.g. build changes, source generators, testing infrastructure, sample creation changes, etc...
- [ ] Tests for the changes have been added (for bug fixes / features) (if applicable)
- [ ] Header has been added to all new source files (run *build/UpdateHeaders.bat*)
- [x] Contains **NO** breaking changes

<!-- If this PR contains a breaking change, please describe the impact and migration path for existing applications below.
     Please note that breaking changes are likely to be rejected within minor release cycles or held until major versions. -->


## Other information
@ghost ghost added Completed 🔥 and removed In-PR 🚀 labels Jun 29, 2021
@ghost ghost locked as resolved and limited conversation to collaborators Nov 3, 2021
This issue was closed.
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Projects
None yet
4 participants