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

Prevent splitting panes into 0 width/height #2401 #2450

Merged

Conversation

richardszalay
Copy link
Contributor

Fixes a crash that can occur when splitting pane that was so small that the target panes would have a width/height of 0, causing DxRenderer to fail when creating the device resources.

This PR prevents both the call to App::AddHorizontal/VerticalSplit and the creation of the TermControl if the split would fail.

Summary of the Pull Request

References

PR Checklist

Detailed Description of the Pull Request / Additional comments

App::_SplitPane calls focusedTab->CanAddHorizontalSplit/CanAddHorizontalSplit before it initializes the TermControl to avoid having to deal with the cleanup. If a split cannot occur, it will simply return.

Question: Should we beep or something here?

It then follows the same naming/flow style as the split operation, so: Tab::CanAddHorizontalSplit -> Pane::CanSplitHorizontal ->Pane::_CanSplit. The public pane methods will handle leaf/child the same as the current Split methods.

_CanSplit reuses existing logic like _root.GetActualWidth/Height, Pane::_GetMinSize, and the Half constant.

Validation Steps Performed

  1. Open a new tab
  2. Attempt to split horizontally/vertically more than 6-8 times

Success: Pane will will eventually stop splitting rather than crashing the process.

Copy link
Member

@zadjii-msft zadjii-msft left a comment

Choose a reason for hiding this comment

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

Overall I'm really happy with this, but I think we need to account for the separator size in Pane::_CanSplit

src/cascadia/TerminalApp/Pane.cpp Show resolved Hide resolved
@ghost ghost added the Needs-Author-Feedback The original author of the issue/PR needs to come back and respond to something label Aug 16, 2019
@ghost ghost removed the Needs-Author-Feedback The original author of the issue/PR needs to come back and respond to something label Aug 17, 2019
@richardszalay
Copy link
Contributor Author

Ah yes - I was originally planning on using _GetPaneSizes as it already contained the separator logic, but couldn't in the end because it relied on the _firstPercent/_secondPercent private members and then forgot to include it in my own implementation.

I've amended the commit to include the separator.

(To be honest, I think a lot of Pane.cpp could be refactored to avoid duplicating logic but since this is my first PR I wanted to keep things simple)

@zadjii-msft
Copy link
Member

(To be honest, I think a lot of Pane.cpp could be refactored to avoid duplicating logic but since this is my first PR I wanted to keep things simple)

I would so very happily review that PR 😄

@richardszalay
Copy link
Contributor Author

@zadjii-msft Are those updates ok? The issue is still marked as requiring changes.

@zadjii-msft
Copy link
Member

Oh, yea I'm happy with that. Sorry I missed the new commit!

@zadjii-msft zadjii-msft added the Needs-Second It's a PR that needs another sign-off label Aug 20, 2019
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.

It feels weird that we have Tab::CanAddHorizontalSplit() and Tab::CanAddVerticalSplit(). Could we instead have Tab::CanAddPaneSplit(Pane::SplitState)? That would cut down on some of the code to maintain.

The same idea applies to Pane.

{
const bool changeWidth = _splitState == SplitState::Vertical;

const Size actualSize{ gsl::narrow_cast<float>(_root.ActualWidth()),
Copy link
Member

Choose a reason for hiding this comment

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

Should this be gsl::narrow_cast or gsl::narrow? I honestly don't know, but I know gsl::narrow_cast can throw an exception and gsl::narrow doesn't.

Copy link
Member

Choose a reason for hiding this comment

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

The other way around. gsl::narrow_cast means shrink it and I don't care if it doesn't fit exactly.

gsl::narrow means if it didn't fit, throw an exception.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@carlos-zamora Since double->float is only going to cause a precision loss, I'm assuming that's preferable to keep using gsl::narrow_cast?

@ghost ghost added the Needs-Author-Feedback The original author of the issue/PR needs to come back and respond to something label Aug 20, 2019
@richardszalay
Copy link
Contributor Author

@carlos-zamora Both the naming and the use of narrow_cast were used to remain consistent with the existing conventions of the class.

I plan on doing a refactor PR as per my comments above, but I didn't want to include it in this PR since it would detract from the fix being made (not to mention that this is my first terminal PR)

If you're happy to merge this as-is, I can follow up with the refactor PR.

@ghost ghost removed the Needs-Author-Feedback The original author of the issue/PR needs to come back and respond to something label Aug 20, 2019
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.

@richardszalay Fair enough. Congrats on your first contribution :)

@DHowett-MSFT DHowett-MSFT merged commit 09d79cb into microsoft:master Aug 20, 2019
@DHowett-MSFT
Copy link
Contributor

Thanks a bunch!

@richardszalay richardszalay deleted the 2401-minimum-split-pane-size branch August 20, 2019 22:48
@ghost ghost removed the Needs-Second It's a PR that needs another sign-off label Aug 21, 2019
@richardszalay richardszalay mentioned this pull request Aug 21, 2019
5 tasks
@ghost
Copy link

ghost commented Aug 27, 2019

🎉Windows Terminal Preview v0.4.2382.0 has been released which incorporates this pull request.:tada:

Handy links:

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Crash when attempting to split pane with insufficient space available
5 participants